#include <bits/stdc++.h>
const long long sz = 1e6 + 5;
using namespace std;
long long read() {
  char c = getchar();
  long long r = 0, f = 1;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') {
    f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    r = r * 10 + c - '0';
    c = getchar();
  }
  return f * r;
}
struct node {
  long long nxt, to;
} e[sz];
long long n, m, w[sz], b[sz], head[sz], cnt, siz[sz];
pair<long long, long long> f[3010][3010];
pair<long long, long long> tmp[sz];
void add_edge(long long x, long long y) {
  e[++cnt] = (node){head[x], y};
  head[x] = cnt;
}
void dfs(long long now, long long fa) {
  f[now][1] = make_pair(0, w[now] - b[now]), siz[now] = 1;
  for (long long i = head[now]; i; i = e[i].nxt) {
    if (e[i].to == fa) continue;
    dfs(e[i].to, now);
    for (long long j = 1; j <= siz[now] + siz[e[i].to] && j <= m; j++)
      tmp[j] = make_pair(0, -1e18);
    for (long long j = 1; j <= siz[now]; j++)
      for (long long k = 1; k <= siz[e[i].to]; k++) {
        long long fi = f[now][j].first + f[e[i].to][k].first;
        if (f[e[i].to][k].second > 0) fi++;
        if (fi > tmp[j + k].first)
          tmp[j + k] = make_pair(fi, f[now][j].second);
        else if (fi == tmp[j + k].first)
          tmp[j + k].second = max(tmp[j + k].second, f[now][j].second);
        if (f[e[i].to][k].second > 0) fi--;
        if (fi > tmp[j + k - 1].first)
          tmp[j + k - 1] =
              make_pair(fi, f[now][j].second + f[e[i].to][k].second);
        else if (fi == tmp[j + k - 1].first)
          tmp[j + k - 1].second = max(tmp[j + k - 1].second,
                                      f[now][j].second + f[e[i].to][k].second);
      }
    siz[now] += siz[e[i].to];
    for (long long j = 1; j <= siz[now]; j++) f[now][j] = tmp[j];
  }
}
signed main() {
  long long T = read();
  while (T--) {
    long long ans = 0;
    n = read(), m = read();
    for (long long i = 1; i <= n; i++) {
      for (long long j = 1; j <= m; j++) f[i][j] = make_pair(0, -1e18);
      head[i] = 0;
    }
    for (long long i = 1; i <= n; i++) b[i] = read();
    for (long long i = 1; i <= n; i++) w[i] = read();
    for (long long i = 1; i < n; i++) {
      long long u = read(), v = read();
      add_edge(u, v), add_edge(v, u);
    }
    dfs(1, 1);
    if (f[1][m].second > 0) ans++;
    ans += f[1][m].first;
    cout << ans << endl;
  }
}
