#include <bits/stdc++.h>
int n, m, cnt, w[3005], u[3005], v[3005], val[3005], vis[3005], ans, d;
std::vector<int> conj[3005];
void dfs(int u) {
  vis[u] = cnt;
  if (w[u] > 0) {
    ans++;
    return;
  }
  for (int i = 0; i < conj[u].size(); ++i) {
    int v = conj[u][i];
    if (vis[v] || w[v] > 0) continue;
    dfs(v);
  }
}
void dfs1(int u, int a1, int a2, int w1) {
  if (vis[u] != a1) return;
  vis[u] = a2;
  w[u] = w1;
  for (int i = 0; i < conj[u].size(); ++i) {
    int v = conj[u][i];
    if (vis[v] != a1) continue;
    dfs1(v, a1, a2, w1);
  }
}
void merge(int u, int v) {
  int a1 = vis[u], a2 = vis[v], w1 = w[u] - w[v];
  dfs1(u, a1, a1, w1);
  dfs1(v, a1, a2, w1);
}
int ok(int u) { return w[u] > 0; }
void solve() {
  cnt = 0;
  ans = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    vis[i] = val[i] = w[i] = 0;
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d);
    w[i] -= d;
    while (conj[i].size()) conj[i].pop_back();
  }
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &d);
    w[i] += d;
  }
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &u[i], &v[i]);
    conj[u[i]].push_back(v[i]);
    conj[v[i]].push_back(u[i]);
  }
  for (int i = 1; i <= n; ++i)
    if (!vis[i]) {
      ++cnt;
      dfs(i);
    }
  for (int i = 1; i <= n; ++i) val[vis[i]] += w[i];
  for (int i = 1; i <= n; ++i) w[i] = val[vis[i]];
  while (cnt > m) {
    int sel = 0, max = -2e9;
    for (int i = 1; i < n; ++i) {
      if (ok(u[i]) == ok(v[i])) continue;
      if (!ok(u[i])) std::swap(u[i], v[i]);
      if (w[u[i]] + w[v[i]] > max) {
        max = w[u[i]] + w[v[i]];
        sel = i;
      }
    }
    cnt--;
    merge(u[sel], v[sel]);
    if (max <= 0) ans--;
  }
  printf("%d\n", ans);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
