#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
const int MAXN = 3013;
const long long LLINF = 2696969696969696969ll;
int TC;
int N, M;
vector<int> edge[MAXN];
long long arr[MAXN];
vector<pair<long long, long long> > dp[MAXN];
long long ans;
vector<pair<long long, long long> > comb(
    vector<pair<long long, long long> > l,
    vector<pair<long long, long long> > r) {
  vector<pair<long long, long long> > res(((int)(l).size()) +
                                          ((int)(r).size()));
  for (auto i = (0); i < (((int)(res).size())); i++) res[i] = {-LLINF, -LLINF};
  for (auto i = (0); i < (((int)(l).size())); i++) {
    pair<long long, long long> p = l[i];
    for (auto j = (0); j < (((int)(r).size())); j++) {
      pair<long long, long long> q = r[j];
      ckmax(res[i + j + 1],
            make_pair(p.first + q.first + (q.second > 0), p.second));
      ckmax(res[i + j], make_pair(p.first + q.first, p.second + q.second));
    }
  }
  return res;
}
void solve(int u, int p) {
  dp[u].push_back({0, arr[u]});
  for (int v : edge[u]) {
    if (v == p) continue;
    solve(v, u);
    dp[u] = comb(dp[u], dp[v]);
  }
}
int32_t main() {
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> TC;
  while (TC--) {
    cin >> N >> M;
    for (auto i = (0); i < (N); i++) {
      edge[i].clear();
      dp[i].clear();
    }
    for (auto i = (0); i < (N); i++) {
      cin >> arr[i];
    }
    for (auto i = (0); i < (N); i++) {
      long long x;
      cin >> x;
      arr[i] = x - arr[i];
    }
    for (auto i = (0); i < (N - 1); i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    solve(0, N);
    ans = dp[0][M - 1].first + (dp[0][M - 1].second > 0);
    cout << ans << '\n';
  }
  return 0;
}
