#include <bits/stdc++.h>
using namespace std;
int t, n, m;
long long w[3005], b[3005];
vector<int> edge[3005];
long long dp[3005][3005];
long long dpx[3005];
long long maxnx[3005];
long long maxn[3005][3005];
int siz[3005];
long long inf = 1e15 + 7;
void dfs(int u, int fa) {
  siz[u] = 1;
  int len = edge[u].size();
  dp[u][1] = 0;
  maxn[u][1] = 0;
  for (int i = 0; i < len; i++) {
    int v = edge[u][i];
    if (v == fa) continue;
    dfs(v, u);
    for (int j = 1; j <= siz[u]; j++) {
      dpx[j] = dp[u][j];
      maxnx[j] = maxn[u][j];
      dp[u][j] = -inf;
      maxn[u][j] = -inf;
    }
    for (int j = 1; j <= siz[u]; j++) {
      if (j > m) break;
      for (int k = 1; k <= siz[v]; k++) {
        if (j + k - 1 > m) break;
        if (dp[u][j + k - 1] < dpx[j] + dp[v][k] ||
            (dp[u][j + k - 1] == dpx[j] + dp[v][k] &&
             maxn[u][j + k - 1] < maxnx[j] + maxn[v][k])) {
          dp[u][j + k - 1] = dpx[j] + dp[v][k];
          maxn[u][j + k - 1] = maxnx[j] + maxn[v][k];
        }
        if (j + k > m) break;
        int tp = (maxn[v][k] > 0);
        if (dp[u][j + k] < dpx[j] + dp[v][k] + tp ||
            (dp[u][j + k] == dpx[j] + dp[v][k] + tp &&
             maxn[u][j + k] < maxnx[j])) {
          dp[u][j + k] = dpx[j] + dp[v][k] + tp;
          maxn[u][j + k] = maxnx[j];
        }
      }
    }
    siz[u] += siz[v];
  }
  for (int i = 1; i <= siz[u]; i++) {
    maxn[u][i] += (w[u] - b[u]);
  }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
    for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
    for (int i = 1; i <= n; i++) edge[i].clear();
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    for (int i = 1; i <= 3002; i++) {
      for (int j = 0; j <= 3002; j++) {
        dp[i][j] = -inf;
        maxn[i][j] = -inf;
      }
    }
    dfs(1, -1);
    printf("%lld\n", dp[1][m] + (maxn[1][m] > 0));
  }
  return 0;
}
