#include <bits/stdc++.h>
using namespace std;
int t, n, m, k, ans;
int tar[6005], nex[6005], fir[3005], cnt;
int siz[3005];
long long A[3005];
pair<int, long long> f[3005][3005], g[3005];
void Add(int a, int b) {
  ++cnt;
  tar[cnt] = b;
  nex[cnt] = fir[a];
  fir[a] = cnt;
}
void Dfs(int r, int fa) {
  siz[r] = 1;
  for (int i = 1; i <= m; i++) f[r][i] = make_pair(-1, 0);
  f[r][1] = make_pair(0, A[r]);
  for (int i = fir[r]; i; i = nex[i]) {
    int v = tar[i];
    if (v != fa) {
      Dfs(v, r);
      int a = min(m, siz[r]), b = min(m, siz[v]);
      for (int j = 1; j <= min(m, a + b); j++) g[j] = make_pair(-1, 0);
      for (int j = 1; j <= a; j++) {
        for (int k = 1; k <= min(b, m - j + 1); k++) {
          if (j + k <= m)
            g[j + k] = max(g[j + k], make_pair(f[r][j].first + f[v][k].first +
                                                   (f[v][k].second > 0),
                                               f[r][j].second));
          g[j + k - 1] =
              max(g[j + k - 1], make_pair(f[r][j].first + f[v][k].first,
                                          f[r][j].second + f[v][k].second));
        }
      }
      for (int j = 1; j <= min(m, a + b); j++) f[r][j] = g[j];
      siz[r] += siz[v];
    }
  }
}
int main() {
  scanf("%d", &t);
  for (; t--;) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &k), A[i] = -k;
    for (int i = 1; i <= n; i++) scanf("%d", &k), A[i] += k;
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      Add(u, v), Add(v, u);
    }
    Dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
    for (int i = 1; i <= n; i++) fir[i] = 0;
    cnt = 0;
  }
}
