#include <bits/stdc++.h>
using namespace std;
const int MAX = (3e3) + 5;
const int dpMAX = (3e3) + 5;
vector<int> mat[MAX];
pair<int, long long> dp[dpMAX][dpMAX];
int vis[dpMAX][dpMAX], ini, B[MAX], W[MAX], chi[MAX], sib[MAX], sz[MAX];
void dfs(int p, int pa) {
  int lc = -1;
  lc = chi[p] = sib[p] = 0;
  for (int x : mat[p]) {
    if (x == pa) {
      continue;
    }
    dfs(x, p);
    (!lc) ? (chi[p] = x) : (sib[lc] = x);
    lc = x;
  }
}
void coun(int p) {
  if (!p) {
    return;
  }
  sz[p] = 1;
  coun(chi[p]);
  coun(sib[p]);
  sz[p] += sz[chi[p]];
  sz[p] += sz[sib[p]];
}
pair<int, long long> rec(int p, int r) {
  if (!p) {
    if (r) cout << r << endl;
    return {0, 0};
  }
  if (vis[p][r] == ini) {
    return dp[p][r];
  }
  vis[p][r] = ini;
  pair<int, long long> temp = {-3000, -(1e14)};
  int cn = chi[p], sn = sib[p];
  for (int t = 0; t <= 1; t++) {
    if (p == 1 && t == 0) {
      continue;
    }
    for (int i = max(0, (r - t) - sz[sn]); i <= min((r - t), sz[cn]); i++) {
      pair<int, long long> c = rec(cn, i);
      pair<int, long long> s = rec(sn, (r - t) - i);
      c.second += (W[p] - B[p]);
      if (t) {
        c.first += (c.second > 0);
        c.second = 0;
      }
      c.first += s.first;
      c.second += s.second;
      temp = max(temp, c);
    }
  }
  return dp[p][r] = temp;
}
void solve() {
  int n, m, u, v;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    mat[i].clear();
    chi[i] = sib[i] = -1;
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &B[i]);
  }
  for (int i = 1; i <= n; i++) {
    scanf("%d", &W[i]);
  }
  for (int i = 1; i <= n - 1; i++) {
    scanf("%d %d", &u, &v);
    mat[u].push_back(v);
    mat[v].push_back(u);
  }
  dfs(1, 1);
  coun(1);
  ini++;
  printf("%d\n", rec(1, m).first);
}
int main() {
  int tc;
  scanf("%d", &tc);
  for (int tt = 1; tt <= tc; tt++) {
    solve();
  }
  return 0;
}
