#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const long long INF = 100000;
const long long MAXN = 100010;
long long N, T, M;
long long Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt;
inline void insert(long long u, long long v) {
  Node[++cnt] = v;
  Next[cnt] = Root[u];
  Root[u] = cnt;
}
pair<long long, long long> f[3010][3010], g[3010];
long long sz[MAXN + 1];
long long val[MAXN + 1];
inline void dp(long long k, long long Fa) {
  for (long long i = 0; i <= M; i++) f[k][i] = make_pair(-INF, 0);
  sz[k] = 1;
  f[k][0] = make_pair(0, val[k]);
  for (long long x = Root[k]; x; x = Next[x]) {
    long long v = Node[x];
    if (v == Fa) continue;
    dp(v, k);
    for (long long i = 0; i <= sz[k] + sz[v]; i++) g[i] = make_pair(-INF, -INF);
    for (long long i = 0; i <= sz[k]; i++) {
      for (long long j = 0; j <= sz[v]; j++) {
        if (f[k][i].first + f[v][j].first > g[i + j].first ||
            (f[k][i].first + f[v][j].first == g[i + j].first &&
             f[k][i].second + f[v][j].second > g[i + j].second))
          g[i + j] = make_pair(f[k][i].first + f[v][j].first,
                               f[k][i].second + f[v][j].second);
      }
    }
    for (long long i = 0; i <= sz[k] + sz[v]; i++) f[k][i] = g[i];
    sz[k] += sz[v];
  }
  if (Fa)
    for (long long i = sz[k]; i >= 0; i--) {
      long long now = f[k][i].first + (f[k][i].second > 0);
      if (f[k][i + 1].first < now ||
          (f[k][i + 1].first == now && f[k][i + 1].second < 0))
        f[k][i + 1] = make_pair(now, 0);
    }
}
int main() {
  T = read();
  while (T--) {
    N = read();
    M = read();
    cnt = 0;
    for (long long i = 1; i <= N; i++) val[i] = -read();
    for (long long i = 1; i <= N; i++) val[i] += read();
    for (long long i = 1; i <= N; i++) Root[i] = 0;
    for (long long i = 1; i < N; i++) {
      long long u = read(), v = read();
      insert(u, v);
      insert(v, u);
    }
    dp(1, 0);
    printf("%I64d\n", f[1][M - 1].first + (f[1][M - 1].second > 0));
  }
  return 0;
}
