#include <bits/stdc++.h>
using namespace std;
int n, k, siz[3005], f[3005][3005];
long long a[3005], g[3005][3005];
vector<int> V[3005];
void DFS(int u, int fz) {
  siz[u] = 1;
  f[u][1] = 0, g[u][1] = a[u];
  for (auto v : V[u])
    if (v != fz) {
      DFS(v, u);
      static int F[3005];
      static long long G[3005];
      for (int i = 1; i <= (siz[u] + siz[v]); ++i)
        F[i] = -1, G[i] = -0x3f3f3f3f3f3f3f3f;
      for (int i = 1; i <= (siz[u]); ++i)
        for (int j = 1; j <= (siz[v]); ++j) {
          if (F[i + j - 1] < f[u][i] + f[v][j] ||
              (F[i + j - 1] == f[u][i] + f[v][j] &&
               G[i + j - 1] < g[u][i] + g[v][j]))
            F[i + j - 1] = f[u][i] + f[v][j], G[i + j - 1] = g[u][i] + g[v][j];
          if (F[i + j] < f[u][i] + f[v][j] + (g[v][j] > 0) ||
              (F[i + j] == f[u][i] + f[v][j] + (g[v][j] > 0) &&
               G[i + j] < g[u][i]))
            F[i + j] = f[u][i] + f[v][j] + (g[v][j] > 0), G[i + j] = g[u][i];
        }
      siz[u] += siz[v];
      for (int i = 1; i <= (siz[u]); ++i) f[u][i] = F[i], g[u][i] = G[i];
    }
}
int main() {
  int tests = 1;
  scanf("%d", &tests);
  while (tests--) {
    int x, y;
    scanf("%d%d", &n, &k);
    for (int i = 1; i <= (n); ++i) scanf("%lld", a + i);
    for (int i = 1; i <= (n); ++i) scanf("%d", &x), a[i] = x - a[i];
    for (int i = 1; i <= (n); ++i) V[i].clear();
    for (int i = 2; i <= (n); ++i)
      scanf("%d%d", &x, &y), V[x].push_back(y), V[y].push_back(x);
    DFS(1, 0);
    printf("%d\n", f[1][k] + (g[1][k] > 0));
  }
  return 0;
}
