#include <bits/stdc++.h>
using namespace std;
vector<int> e[3010];
int b[3010], w[3010], m, ch[3010];
long long a[3010];
int dp[3010][3010];
pair<int, long long> dp2[3010][3010], tmp[3010];
pair<int, long long> merge(pair<int, long long> x, pair<int, long long> y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
inline int ev(pair<int, long long> x) { return x.first + (x.second > 0); }
void dfs(int v, int p = -1) {
  ch[v] = 1;
  dp2[v][0] = make_pair(0, a[v]);
  for (int i = 0; i < e[v].size(); i++) {
    int u = e[v][i];
    if (u == p) continue;
    dfs(u, v);
    ch[v] += ch[u];
    for (int j = 0; j < min(ch[v], m); j++) {
      tmp[j] = make_pair(-m - 1, 0);
    }
    for (int j = min(ch[v], m) - 1; j >= 0; j--) {
      for (int k = max(j - ch[v] + ch[u], 0); k <= min(min(ch[u], m), j); k++) {
        if (k < ch[u] && k < m)
          tmp[j] = max(tmp[j], merge(dp2[v][j - k], dp2[u][k]));
        if (k)
          tmp[j] = max(tmp[j], merge(dp2[v][j - k], make_pair(dp[u][k], 0)));
      }
    }
    for (int j = 0; j < min(ch[v], m); j++) {
      dp2[v][j] = tmp[j];
    }
  }
  for (int i = 0; i < min(ch[v], m); i++) {
    dp[v][i + 1] = ev(dp2[v][i]);
  }
}
void solve() {
  int n;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) {
    scanf("%d", &b[i]);
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &w[i]);
  }
  for (int i = 0; i < n; i++) {
    a[i] = w[i] - b[i];
    e[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(0);
  printf("%d\n", max(0, dp[0][m]));
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
