#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
struct apple {
  int x;
  long long v;
  bool operator<(const apple &other) const {
    return x < other.x || (x == other.x && v < other.v);
  }
  apple() {}
  apple(int a, long long b) {
    x = a;
    v = b;
  }
} f[N][N], ff[N];
struct pear {
  int be, to;
} edge[N * 2];
long long b[N], a[N];
int t[N], size[N], vist[N];
int k;
void addedge(int x, int y) {
  edge[++k].to = y;
  edge[k].be = t[x];
  t[x] = k;
}
void dfs(int x) {
  int xx, p, i, j;
  vist[x] = 1;
  size[x] = 1;
  f[x][1] = apple(0, b[x] - a[x]);
  p = t[x];
  while (p) {
    xx = edge[p].to;
    if (!vist[xx]) {
      dfs(xx);
      for (i = 1; i <= size[x] + size[xx]; i++) ff[i] = apple(-1, 0);
      for (i = 1; i <= size[xx]; i++) {
        for (j = size[x]; j >= 1; j--) {
          ff[i + j - 1] = max(ff[i + j - 1], apple(f[x][j].x + f[xx][i].x,
                                                   f[x][j].v + f[xx][i].v));
          ff[j + i] =
              max(ff[j + i],
                  apple(f[x][j].x + f[xx][i].x + (f[xx][i].v > 0), f[x][j].v));
        }
      }
      size[x] += size[xx];
      for (i = 1; i <= size[x]; i++) f[x][i] = ff[i];
    }
    p = edge[p].be;
  }
}
int main() {
  int T, n, m, i, j, x, y;
  scanf("%d", &T);
  while (T) {
    T--;
    scanf("%d%d", &n, &m);
    k = 0;
    for (i = 1; i <= n; i++) t[i] = 0, vist[i] = 0;
    for (i = 1; i <= n; i++)
      for (j = 0; j <= i; j++) f[i][j] = apple(-1, 0);
    for (i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (i = 1; i <= n; i++) scanf("%lld", &b[i]);
    for (i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      addedge(x, y);
      addedge(y, x);
    }
    dfs(1);
    printf("%d\n", f[1][m].x + (f[1][m].v > 0));
  }
  return 0;
}
