#include <bits/stdc++.h>
using namespace std;
struct Edge {
  long long v, nxt;
} e[3005 << 1 | 1];
long long cnt = 0, last[3005];
void adde(long long u, long long v) {
  e[++cnt].v = v;
  e[cnt].nxt = last[u], last[u] = cnt;
}
long long a[3005], size[3005];
std::pair<long long, long long> f[3005][3005], tmp[3005];
void upd(std::pair<long long, long long> &a,
         std::pair<long long, long long> t) {
  if (t > a) a = t;
}
void dp(long long u, long long fa = 0) {
  size[u] = 1;
  f[u][1] = std::pair<long long, long long>(0, a[u]);
  for (long long i = last[u]; i; i = e[i].nxt) {
    long long v = e[i].v;
    if (v == fa) continue;
    dp(v, u);
    for (long long j = 1; j <= size[u] + size[v]; ++j)
      tmp[j] = std::pair<long long, long long>(-1, 0);
    for (long long j = 1; j <= size[u]; ++j)
      for (long long k = 1; k <= size[v]; ++k) {
        upd(tmp[j + k],
            std::pair<long long, long long>(
                f[u][j].first + f[v][k].first + (f[v][k].second > 0),
                f[u][j].second));
        upd(tmp[j + k - 1],
            std::pair<long long, long long>(f[u][j].first + f[v][k].first,
                                            f[u][j].second + f[v][k].second));
      }
    for (long long j = 1; j <= size[u] + size[v]; ++j) f[u][j] = tmp[j];
    size[u] += size[v];
  }
}
int main() {
  long long task;
  cin >> task;
  while (task--) {
    long long n, m;
    cin >> n >> m;
    long long temp;
    for (long long i = 1; i <= n; ++i) {
      cin >> temp;
      a[i] = -temp;
    }
    for (long long i = 1; i <= n; ++i) {
      cin >> temp;
      a[i] += temp;
    }
    for (long long i = 1; i < n; ++i) {
      long long u, v;
      cin >> u >> v;
      adde(u, v), adde(v, u);
    }
    dp(1);
    printf("%lld\n", f[1][m].first + (f[1][m].second > 0));
    cnt = 0;
    for (long long i = 1; i <= n; ++i) {
      last[i] = 0;
      for (long long j = 1; j <= m; ++j)
        f[i][j] = std::pair<long long, long long>(0, 0);
    }
  }
  return 0;
}
