#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
int n, m, a[N], par[N];
vector<int> adj[N];
int get_par(int u) { return par[u] < 0 ? u : par[u] = get_par(par[u]); }
bool merge(int u, int v) {
  if ((u = get_par(u)) == (v = get_par(v))) return false;
  if (par[u] > par[v]) swap(u, v);
  par[u] += par[v], m--;
  a[par[v] = u] += a[v];
  return true;
}
int f(int u) { return a[get_par(u)]; }
void read_input() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i] = x - a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[--u].push_back(--v);
    adj[v].push_back(u);
  }
}
void solve() {
  m = n - m;
  memset(par, -1, sizeof par);
  while (m > 0) {
    bool flag = false;
    for (int u = 0; u < n; u++)
      if (f(u) >= 0)
        for (auto v : adj[u])
          if (f(v) >= 0) flag |= merge(u, v);
    for (int u = 0; u < n; u++)
      if (f(u) >= 0)
        for (auto v : adj[u])
          if (f(u) + f(v) < 0) {
            flag = merge(u, v);
            break;
          }
    int mn = -1, mx = -1;
    for (int u = 0; u < n; u++)
      if (f(u) >= 0 && (!~mn || f(u) < f(mn))) mn = u;
    for (int u = 0; u < n; u++)
      if (get_par(u) == get_par(mn))
        for (auto v : adj[u])
          if (f(v) < 0 && (!~mx || f(v) < f(mx))) mx = v;
    if (!flag && ~mn && ~mx) {
      flag = merge(mn, mx);
      continue;
    }
    for (int u = 0; !flag && u < n; u++)
      for (auto v : adj[u])
        if (merge(u, v)) {
          flag = true;
          break;
        }
  }
}
void write_output() {
  int ans = 0;
  for (int u = 0; u < n; u++) {
    adj[u].clear();
    ans += get_par(u) == u && f(u) < 0;
  }
  cout << ans << endl;
}
void test_cases() {
  int t;
  cin >> t;
  while (t--) {
    read_input();
    solve();
    write_output();
  }
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  test_cases();
  return 0;
}
