#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmin(T &x, T y) {
  return x > y ? x = y, 1 : 0;
}
template <typename T>
bool chkmax(T &x, T y) {
  return x < y ? x = y, 1 : 0;
}
int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, tot;
long long a[3005], b[3005], v[6005], nxt[6005], h[3005], siz[3005];
pair<long long, long long> d[3005][3005], tmp[3005];
void addedge(int x, int y) {
  v[++tot] = y;
  nxt[tot] = h[x];
  h[x] = tot;
  v[++tot] = x;
  nxt[tot] = h[y];
  h[y] = tot;
}
void dfs(int u, int fa) {
  d[u][0] = make_pair(0, a[u]);
  siz[u] = 1;
  for (int p = h[u]; p; p = nxt[p]) {
    if (v[p] == fa) continue;
    dfs(v[p], u);
    for (int i = 0; i <= min((long long)m, siz[u] + siz[v[p]]); i++)
      tmp[i] = make_pair(0, -(1ll << 60));
    for (int i = 0; i <= min(siz[u], (long long)m); i++) {
      for (int j = 0; j <= min(siz[v[p]], (long long)m - i); j++) {
        chkmax(tmp[i + j], make_pair(d[u][i].first + d[v[p]][j].first,
                                     d[u][i].second + d[v[p]][j].second));
        chkmax(tmp[i + j + 1], make_pair(d[u][i].first + d[v[p]][j].first +
                                             (d[v[p]][j].second > 0),
                                         d[u][i].second));
      }
    }
    siz[u] += siz[v[p]];
    for (int i = 0; i <= min(siz[u], (long long)m); i++) d[u][i] = tmp[i];
  }
}
int main() {
  int T = readint();
  while (T--) {
    n = readint();
    m = readint();
    memset(d, 0, sizeof(d));
    for (int i = 1; i <= n; i++) h[i] = 0;
    tot = 0;
    for (int i = 1; i <= n; i++) b[i] = readint();
    for (int i = 1; i <= n; i++) a[i] = readint() - b[i];
    for (int i = 1; i < n; i++) addedge(readint(), readint());
    dfs(1, -1);
    printf("%lld\n", d[1][m - 1].first + (d[1][m - 1].second > 0));
  }
  return 0;
}
