#include <bits/stdc++.h>
using namespace std;
void read(long long &x) {
  char ch = getchar();
  x = 0;
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - 48, ch = getchar();
}
const long long N = 3005, M = N << 1;
long long n, m, a[N], b[N];
long long cnt, h[N], nxt[M], to[M], sz[N];
void add(long long u, long long v) {
  to[++cnt] = v, nxt[cnt] = h[u], h[u] = cnt;
}
pair<long long, long long> f[N][N], t[N];
void dfs(long long u, long long la) {
  sz[u] = 1;
  f[u][1] = {0, a[u]};
  for (long long i = h[u], v; i; i = nxt[i]) {
    if ((v = to[i]) == la) continue;
    dfs(v, u);
    for (long long j = 1; j <= sz[u] + sz[v]; ++j) t[j] = {-1, 0};
    for (long long j = 1; j <= sz[u]; ++j)
      for (long long k = 1; k <= sz[v]; ++k) {
        t[j + k] =
            max(t[j + k], {f[v][k].first + f[u][j].first + (f[v][k].second > 0),
                           f[u][j].second});
        t[j + k - 1] = max(t[j + k - 1], {f[v][k].first + f[u][j].first,
                                          f[v][k].second + f[u][j].second});
      }
    sz[u] += sz[v];
    for (long long j = 1; j <= sz[u]; ++j) f[u][j] = t[j];
  }
}
signed main() {
  long long T;
  read(T);
  while (T--) {
    read(n), read(m);
    cnt = 0;
    for (long long i = 1; i <= n; ++i) h[i] = 0;
    for (long long i = 1; i <= n; ++i)
      for (long long j = 1; j <= m; ++j) f[i][j] = {0, 0};
    for (long long i = 1; i <= n; ++i) read(b[i]);
    for (long long i = 1; i <= n; ++i) read(a[i]), a[i] -= b[i];
    for (long long i = 1, u, v; i < n; ++i)
      read(u), read(v), add(u, v), add(v, u);
    dfs(1, 0);
    printf("%lld\n", f[1][m].first + (f[1][m].second > 0));
  }
  return 0;
}
