#include <bits/stdc++.h>
using namespace std;
const int N = 3005, M = N << 1;
int T, n, m, a[N], hd[N], V[M], nx[M], t;
struct O {
  int x;
  long long y;
};
vector<O> f[N], C;
bool J(O A, int x, long long y) { return A.x < x || (A.x == x && A.y < y); }
vector<O> hb(vector<O> A, vector<O> B) {
  int x = A.size(), y = B.size();
  C.clear();
  for (int i = 0; i < x + y; i++) C.push_back((O){-1, 0});
  for (int i = 0; i < x; i++)
    for (int j = 0; j < y; j++) {
      int u = A[i].x + B[j].x;
      long long v = A[i].y + B[j].y;
      if (J(C[i + j], u - (A[i].y > 0) - (B[j].y > 0) + (v > 0), v))
        C[i + j] = (O){u - (A[i].y > 0) - (B[j].y > 0) + (v > 0), v};
      if (J(C[i + j + 1], u, A[i].y)) C[i + j + 1] = (O){u, A[i].y};
    }
  return C;
}
void dfs(int x, int fr) {
  for (int i = hd[x]; i; i = nx[i])
    if (V[i] != fr) dfs(V[i], x), f[x] = hb(f[x], f[V[i]]);
}
void add(int u, int v) {
  nx[++t] = hd[u];
  V[hd[u] = t] = v;
}
void work() {
  scanf("%d%d", &n, &m);
  t = 0;
  for (int i = 1; i <= n; i++)
    f[i].clear(), f[i].push_back((O){0, 0}), hd[i] = 0;
  for (int i = 1, x; i <= n; i++) scanf("%d", &x), f[i][0].y -= x;
  for (int i = 1, x; i <= n; i++)
    scanf("%d", &x), f[i][0].y += x, f[i][0].x = f[i][0].y > 0;
  for (int i = 1, u, v; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
  dfs(1, 0);
  printf("%d\n", f[1][m - 1].x);
}
int main() {
  for (scanf("%d", &T); T--; work())
    ;
  return 0;
}
