#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
struct edge {
  int v;
  edge *next;
} pool[3 * N], *h[N];
int n, m, top;
int a[N], size[N];
int f[N][N], t_f[N];
long long g[N][N], t_g[N];
void upd(int i, int x, long long y) {
  if (x > t_f[i])
    t_f[i] = x, t_g[i] = y;
  else if (x == t_f[i])
    if (y > t_g[i]) t_g[i] = y;
}
void addedge(int u, int v) {
  edge *tmp = &pool[++top];
  tmp->v = v;
  tmp->next = h[u];
  h[u] = tmp;
}
void dfs(int u, int pre) {
  size[u] = 1;
  g[u][1] = a[u];
  if (a[u] > 0)
    f[u][1] = 1;
  else
    f[u][1] = 0;
  for (edge *tmp = h[u]; tmp; tmp = tmp->next) {
    int v = tmp->v;
    if (v == pre) continue;
    dfs(v, u);
    for (int i = 1; i <= min(size[u] + size[v] + 1, m + 1); i++)
      t_f[i] = 0, t_g[i] = -0x3f3f3f3f3f3f3f3fll;
    for (int i = 1; i <= size[u]; i++) {
      for (int j = 1; j <= size[v] && i + j - 1 <= m; j++) {
        long long res = g[u][i] + g[v][j];
        int flag = 0;
        if (g[u][i] + g[v][j] > 0) flag++;
        if (g[u][i] > 0) flag--;
        if (g[v][j] > 0) flag--;
        upd(i + j - 1, flag + f[u][i] + f[v][j], g[u][i] + g[v][j]);
        upd(i + j, f[u][i] + f[v][j], g[u][i]);
      }
    }
    size[u] += size[v];
    for (int i = 1; i <= min(size[u], m + 1); i++) {
      f[u][i] = t_f[i];
      g[u][i] = t_g[i];
    }
  }
}
void init() {
  int x, y;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &x);
    a[i] = x - a[i];
  }
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &x, &y);
    addedge(x, y);
    addedge(y, x);
  }
  dfs(1, 0);
  printf("%d\n", f[1][m]);
  top = -1;
  for (int i = 1; i <= n + 1; i++)
    for (int j = 1; j <= m + 1; j++) f[i][j] = g[i][j] = 0;
  for (int i = 1; i <= n + 1; i++) a[i] = size[i] = 0;
  for (int i = 1; i <= m + 1; i++) t_f[i] = t_g[i] = 0;
  for (int i = 1; i <= n + 1; i++) h[i] = NULL;
}
int main() {
  int T;
  cin >> T;
  for (int i = 1; i <= T; i++) init();
  return 0;
}
