#include <bits/stdc++.h>
using namespace std;
long long T;
long long n, m;
long long b[3005], w[3005];
vector<long long> G[3005];
long long num[3005];
pair<long long, long long> dp[3005][3005], dp2[3005][3005];
void dfs(long long v, long long p) {
  num[v] = 1;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == p) continue;
    dfs(G[v][i], v);
    num[v] += num[G[v][i]];
  }
  for (int i = 0; i <= G[v].size(); i++) {
    for (int j = 0; j <= num[v]; j++) {
      dp2[i][j] = pair<long long, long long>(-1e18, -1e18);
    }
  }
  dp2[0][0] = pair<long long, long long>(0LL, w[v] - b[v]);
  long long sum = 0;
  for (int i = 0; i < G[v].size(); i++) {
    long long u = G[v][i];
    if (G[v][i] == p) {
      for (int j = 0; j <= sum; j++) dp2[i + 1][j] = dp2[i][j];
      continue;
    }
    for (int j = 0; j <= sum; j++) {
      for (int k = 0; k <= num[u]; k++) {
        pair<long long, long long> p = dp2[i][j];
        p.first += dp[u][k].first;
        if (dp[u][k].second > 0) p.first++;
        if (j + k + 1 <= sum + num[u])
          dp2[i + 1][j + k + 1] = max(dp2[i + 1][j + k + 1], p);
        p = dp2[i][j];
        p.first += dp[u][k].first;
        p.second += dp[u][k].second;
        if (j + k <= sum + num[u])
          dp2[i + 1][j + k] = max(dp2[i + 1][j + k], p);
      }
    }
    sum += num[u];
  }
  for (int j = 0; j <= num[v]; j++) dp[v][j] = dp2[(int)G[v].size()][j];
}
int main(void) {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> T;
  for (int t = 0; t < T; t++) {
    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 = 1; i <= n; i++) G[i].clear();
    long long u, v;
    for (int i = 1; i <= n - 1; i++) {
      cin >> u >> v;
      G[u].push_back(v);
      G[v].push_back(u);
    }
    dfs(1, -1);
    long long ans = dp[1][m - 1].first;
    if (dp[1][m - 1].second > 0) ans++;
    cout << ans << "\n";
  }
  flush(cout);
  return 0;
}
