#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define rev(i,s,e) for(i64 (i) = (s);(i) --> (e);)
#define all(x) x.begin(),x.end()

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) noexcept {
  return std::vector<T>(n, std::forward<T>(val));
}

template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) noexcept {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
i64 N, M;
vector<i64> A;

vector<vector<i64>> G;

vector<vector<pair<i64, i64>>> dp(3030);

void dfs(i64 v, i64 f) {
  dp[v].resize(1);
  dp[v][0] = { 0, A[v] };
  for(auto t: G[v]) {
    if(f == t) continue;
    dfs(t, v);
    vector<pair<i64, i64>> next(dp[v].size() + dp[t].size(), { 0, -(i64)1e9 });
    rep(i,0,dp[v].size()) rep(j,0,dp[t].size()) {
      next[i + j] = std::max(next[i + j], pair<i64, i64>(dp[v][i].first + dp[t][j].first, dp[v][i].second + dp[t][j].second));
      if(dp[t][j].second > 0) {
        next[i + j + 1] = std::max(next[i + j + 1], pair<i64, i64>(dp[v][i].first + dp[t][j].first + 1, dp[v][i].second));
      }
      else {
        next[i + j + 1] = std::max(next[i + j + 1], pair<i64, i64>(dp[v][i].first + dp[t][j].first, dp[v][i].second));
      }
    }
    swap(dp[v], next);
  }
  /*
  cout << "------" << v << endl;
  rep(i,0,dp[v].size()) {
    cout << i << " = " << dp[v][i].first << " ( " << dp[v][i].second << endl;
  }
  */
}

void solve() {
  cin >> N >> M;
  A.resize(N);
  rep(i,0,N) {
    i64 x;
    cin >> x;
    A[i] = -x;
  }
  rep(i,0,N) {
    i64 x;
    cin >> x;
    A[i] += x;
  }
  G.assign(N, vector<i64>());
  rep(i,0,N-1) {
    i64 x, y;
    cin >> x >> y;
    x--;
    y--;
    G[x].push_back(y);
    G[y].push_back(x);
  }

  dfs(0, -1);

  i64 ans = 0;
  rep(i,0,M) {
    if(i >= dp[0].size()) break;
    ans = std::max(ans, dp[0][i].first);
    if(i < M && dp[0][i].second > 0) {
      ans = std::max(ans, dp[0][i].first + 1);
    }
  }
  cout << ans << endl;
}

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  i64 T;
  cin >> T;
  while(T--) {
    solve();
  }
}
