#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int ret = 0;
  char c = getchar();
  while (c < 48 || c > 57) c = getchar();
  while (c >= 48 && c <= 57) ret = ret * 10 + c - 48, c = getchar();
  return ret;
}
int u, v, _f[3005][3005], si[3005], n, m, T, c[6005][2], a[3005], tot, w[3005],
    b[3005], f[3005][3005];
long long g[3005][3005], _g[3005][3005];
void df(int p, int pr) {
  si[p] = 1;
  int u;
  for (int o = a[p]; o; o = c[o][1]) {
    u = c[o][0];
    if (u == pr) continue;
    df(u, p);
    si[p] += si[u];
  }
  si[p] = min(si[p], m);
}
void dfs(int p, int pr) {
  f[p][1] = w[p] > b[p];
  g[p][1] = w[p] - b[p];
  int u, D = 1, e, uu, h, op;
  for (int o = a[p]; o; o = c[o][1]) {
    u = c[o][0];
    if (u == pr) continue;
    dfs(u, p);
    e = si[u];
    h = min(D + e, m);
    for (int i = 1; i <= h; ++i)
      _f[p][i] = f[p][i], _g[p][i] = g[p][i], f[p][i] = -1;
    for (int i = 1; i <= e; ++i) {
      op = min(D, m - i + 1);
      for (int j = op; j >= 1; --j) {
        if (_f[p][j] + f[u][i] > f[p][j + i]) {
          f[p][j + i] = _f[p][j] + f[u][i];
          g[p][j + i] = _g[p][j];
        } else {
          if (_f[p][j] + f[u][i] == f[p][j + i]) {
            g[p][j + i] = max(g[p][j + i], _g[p][j]);
          }
        }
        uu = (_g[p][j] + g[u][i] > 0) - (_g[p][j] > 0) - (g[u][i] > 0);
        if (_f[p][j] + f[u][i] + uu > f[p][j + i - 1]) {
          f[p][j + i - 1] = _f[p][j] + f[u][i] + uu;
          g[p][j + i - 1] = _g[p][j] + g[u][i];
        } else {
          if (_f[p][j] + f[u][i] + uu == f[p][j + i - 1]) {
            g[p][j + i - 1] = max(g[p][j + i - 1], _g[p][j] + g[u][i]);
          }
        }
      }
    }
    D += e;
  }
}
int main() {
  T = read();
  while (T--) {
    n = read();
    m = read();
    for (int i = 1; i <= n; ++i) memset(f[i], -1, (m + 1) * sizeof(int));
    for (int i = 1; i <= n; ++i) b[i] = read();
    for (int i = 1; i <= n; ++i) w[i] = read();
    memset(a, 0, (n + 1) * sizeof(int));
    tot = 0;
    for (int i = 1; i < n; ++i) {
      u = read();
      v = read();
      c[++tot][0] = v;
      c[tot][1] = a[u];
      a[u] = tot;
      c[++tot][0] = u;
      c[tot][1] = a[v];
      a[v] = tot;
    }
    df(1, 0);
    dfs(1, 0);
    printf("%d\n", f[1][m]);
  }
}
