#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int n, m, sl, fh, a[3010], siz[3010];
pair<int, long long> f[3010], dp[3010][3010];
int t, h[3010];
struct Tre {
  int to, nxt;
} e[6010];
int rd() {
  sl = 0;
  fh = 1;
  char ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') fh = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') sl = sl * 10 + ch - '0', ch = getchar();
  return sl * fh;
}
void add(int u, int v) {
  e[++t] = (Tre){v, h[u]};
  h[u] = t;
  e[++t] = (Tre){u, h[v]};
  h[v] = t;
}
void upd(pair<int, long long> &x, pair<int, long long> y) {
  if (x < y) x = y;
}
void dfs(int u, int fa) {
  int v;
  siz[u] = 1;
  dp[u][0] = make_pair(0, a[u]);
  for (int i = h[u]; i; i = e[i].nxt)
    if ((v = e[i].to) != fa) {
      dfs(v, u);
      for (int j = 0; j <= m && j < siz[u] + siz[v]; ++j)
        f[j] = make_pair(0, -inf);
      for (int j = 0; j <= m && j < siz[u]; ++j)
        for (int k = 0; j + k <= m && k < siz[v]; ++k)
          upd(f[j + k], make_pair(dp[u][j].first + dp[v][k].first,
                                  dp[u][j].second + dp[v][k].second)),
              upd(f[j + k + 1], make_pair(dp[u][j].first + dp[v][k].first +
                                              (dp[v][k].second > 0),
                                          dp[u][j].second));
      siz[u] += siz[v];
      for (int j = 0; j <= m && j < siz[u]; ++j) dp[u][j] = f[j];
    }
}
int main() {
  for (int x, y, T = rd(); T; --T) {
    memset(h + 1, 0, n << 2);
    t = 0;
    n = rd();
    m = rd();
    for (int i = 1; i <= n; ++i) a[i] = -rd();
    for (int i = 1; i <= n; ++i) a[i] += rd();
    for (int i = 1; i < n; ++i) x = rd(), y = rd(), add(x, y);
    dfs(1, 0);
    printf("%d\n", dp[1][m - 1].first + (dp[1][m - 1].second > 0));
  }
  return 0;
}
