#include <bits/stdc++.h>
using namespace std;
const int intINF = 1e9;
const long long llINF = 2e18;
int read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
long long readll() {
  long long v = 0, f = 1;
  char c = getchar();
  while (c < 48 || 57 < c) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar();
  return v * f;
}
pair<int, long long> dp[3333][3333], f[3333];
int head[3333], vet[6666], nxt[6666], sz[3333], n, m, tot;
void predo() {}
void add(int a, int b) {
  nxt[++tot] = head[a];
  vet[tot] = b;
  head[a] = tot;
}
void dfs(int u, int fa) {
  int e = head[u];
  sz[u] = 1;
  while (e) {
    int v = vet[e];
    if (v != fa) {
      dfs(v, u);
      for (int i = (int)1; i <= (int)m; i++) f[i] = make_pair(-intINF, -llINF);
      for (int i = (int)1; i <= (int)sz[u]; i++)
        for (int j = (int)1; j <= (int)sz[v]; j++) {
          f[i + j - 1] =
              max(f[i + j - 1], make_pair(dp[u][i].first + dp[v][j].first,
                                          dp[u][i].second + dp[v][j].second));
          f[i + j] = max(f[i + j], make_pair(dp[u][i].first + dp[v][j].first +
                                                 (dp[v][j].second > 0),
                                             dp[u][i].second));
        }
      for (int i = (int)1; i <= (int)m; i++) dp[u][i] = f[i];
      sz[u] += sz[v];
    }
    e = nxt[e];
  }
}
void init() {
  n = read(), m = read();
  for (int i = (int)1; i <= (int)n; i++) head[i] = 0;
  tot = 0;
  for (int i = (int)1; i <= (int)n; i++) dp[i][1] = make_pair(0, 0);
  for (int i = (int)1; i <= (int)n; i++) {
    int x = read();
    dp[i][1].second -= x;
  }
  for (int i = (int)1; i <= (int)n; i++) {
    int x = read();
    dp[i][1].second += x;
  }
  for (int i = (int)1; i <= (int)n - 1; i++) {
    int x = read(), y = read();
    add(x, y);
    add(y, x);
  }
}
void solve() {
  dfs(1, 0);
  printf("%d\n", dp[1][m].first + (dp[1][m].second > 0));
}
int main() {
  predo();
  int cas = read();
  while (cas--) {
    init();
    solve();
  }
  return 0;
}
