#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int maxn = 3e3 + 5;
int b[maxn], w[maxn], n, m;
pair<int, int> f[maxn][maxn], tg[maxn];
vector<int> ke[maxn];
int dfs(int u, int pr) {
  int szu = 1;
  f[u][1] = {0, w[u] - b[u]};
  for (auto& v : ke[u])
    if (v != pr) {
      int szv = dfs(v, u);
      for (int i = 0; i <= szu + szv + 1; i++) tg[i] = {-1, 0};
      for (int i = 1; i <= szu; i++)
        for (int j = 1; j <= szv; j++) {
          int k = i + j - 1;
          tg[k] = max(tg[k], {f[u][i].first + f[v][j].first,
                              f[u][i].second + f[v][j].second});
          k = i + j;
          tg[k] =
              max(tg[k], {f[u][i].first + f[v][j].first + (f[v][j].second > 0),
                          f[u][i].second});
        }
      for (int i = 0; i <= szu + szv + 1; i++) f[u][i] = tg[i];
      szu += szv;
    }
  return szu;
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) cin >> w[i];
  for (int i = 0; i <= n; i++) ke[i].clear();
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    cin >> x >> y;
    ke[x].push_back(y), ke[y].push_back(x);
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) f[i][j] = {0, 0};
  dfs(1, 0);
  int res = f[1][m].first + (f[1][m].second > 0);
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  int t;
  cin >> t;
  while (t--) solve();
}
