#include <bits/stdc++.h>
using namespace std;
template <typename T>
void cetak(T t) {
  cout << t << ')' << endl;
}
template <typename T, typename... V>
void cetak(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ", ";
  cetak(v...);
}
const int MOD = 1e9 + 7;
const int mx = 3e5 + 10;
int cari(int x, vector<int> &par) {
  if (par[x] == x) return x;
  return par[x] = cari(par[x], par);
}
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n), b(n), u(n), v(n), par(n);
  vector<long long> sum(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 1; i < n; i++) {
    cin >> u[i] >> v[i];
    u[i] -= 1;
    v[i] -= 1;
  }
  iota(par.begin(), par.end(), 0);
  for (int i = 0; i < n; i++) sum[i] = b[i] - a[i];
  int sampai = n - 1;
  for (int i = n; i > m; i--) {
    int di = -1;
    long long maks = -1e18;
    for (int j = 1; j <= sampai; j++) {
      if (sum[u[j]] <= 0 && sum[v[j]] <= 0) {
        maks = max(maks, sum[u[j]] + sum[v[j]]);
        if (maks == sum[u[j]] + sum[v[j]]) {
          di = j;
        }
      }
    }
    if (di == -1) {
      long long maks = -1e18;
      for (int j = 1; j <= sampai; j++) {
        if (sum[u[j]] + sum[v[j]] > 0 && (sum[u[j]] <= 0 || sum[v[j]] <= 0)) {
          di = j;
          maks = max(maks, sum[u[j]] + sum[v[j]]);
          if (maks == sum[u[j]] + sum[v[j]]) {
            di = j;
          }
        }
      }
    }
    if (di == -1) {
      long long maks = -1e18;
      for (int j = 1; j <= sampai; j++) {
        maks = max(maks, sum[u[j]] + sum[v[j]]);
        if (maks == sum[u[j]] + sum[v[j]]) {
          di = j;
        }
      }
    }
    int x = cari(u[di], par);
    int y = cari(v[di], par);
    par[x] = y;
    sum[y] += sum[x];
    swap(u[di], u[sampai]);
    swap(v[di], v[sampai]);
    sampai -= 1;
  }
  int jaw = 0;
  for (int i = 0; i < n; i++) {
    if (cari(i, par) == i) {
      if (sum[i] > 0) jaw += 1;
    }
  }
  cout << jaw << '\n';
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
