#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chmin(T &x, const T &y) {
  if (x > y) x = y;
}
template <typename T>
void chmax(T &x, const T &y) {
  if (x < y) x = y;
}
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
const long long N = 3000 + 10;
long long n, m, val[N], head[N], cnt, sz[N];
pair<long long, long long> f[N][N], tmp[N];
struct node {
  long long to, next;
} edge[N << 1];
inline void add(long long u, long long v) {
  edge[++cnt] = {v, head[u]};
  head[u] = cnt;
}
inline void up(pair<long long, long long> &x, pair<long long, long long> y) {
  if (y > x) x = y;
}
inline void dfs(long long u, long long fa) {
  f[u][1] = pair<long long, long long>(0, val[u]);
  sz[u] = 1;
  for (long long i = head[u]; i; i = edge[i].next) {
    long long v = edge[i].to;
    if (v == fa) continue;
    dfs(v, u);
    for (long long j = 1; j <= min(sz[v] + sz[u], m); j++)
      tmp[j] = pair<long long, long long>(-1, 0);
    for (long long j = 1; j <= sz[u]; j++)
      for (long long k = 1; k <= sz[v]; k++) {
        up(tmp[j + k], pair<long long, long long>(
                           f[u][j].first + f[v][k].first + (f[v][k].second > 0),
                           f[u][j].second));
        up(tmp[j + k - 1],
           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 <= min(sz[v] + sz[u], m); j++) f[u][j] = tmp[j];
    sz[u] += sz[v];
  }
}
signed main() {
  long long t = read();
  while (t--) {
    n = read(), m = read();
    long long u, v;
    memset(head, 0, sizeof(head));
    cnt = 0;
    for (long long i = 1; i <= n; i++)
      for (long long j = 1; j <= m; j++)
        f[i][j] = pair<long long, long long>(0, 0);
    for (long long i = 1; i <= n; i++) val[i] = read();
    for (long long i = 1; i <= n; i++) val[i] = read() - val[i];
    for (long long i = 1; i < n; i++) {
      u = read(), v = read();
      add(u, v), add(v, u);
    }
    dfs(1, 0);
    cout << f[1][m].first + (f[1][m].second > 0) << endl;
  }
  return 0;
  ;
}
