#include <bits/stdc++.h>
using namespace std;
int n, m;
long long v[3005], s[3005];
basic_string<int> e[3005];
void dfs(int x, int p) {
  for (int y : e[x]) {
    if (y == p) continue;
    dfs(y, x);
    s[x] += s[y];
  }
  s[x] += v[x];
}
int sol;
bool cut[3005];
long long dfs2(int x, int p) {
  long long z = v[x];
  for (int y : e[x]) {
    if (y == p) continue;
    z += dfs2(y, x);
  }
  if (cut[x]) {
    sol += z > 0;
    return 0;
  } else {
    return z;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cerr.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> v[i];
      e[i].clear();
      cut[i] = 0;
      sol = 0;
    }
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      v[i] = x - v[i];
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      e[u] += v;
      e[v] += u;
    }
    dfs(1, 1);
    vector<pair<long long, int>> w;
    for (int i = 1; i <= n; i++)
      w.emplace_back(i == 1 ? long long(1e18) : s[i], i);
    sort(w.begin(), w.end(), greater<pair<long long, int>>());
    for (int i = 0; i < m; i++) {
      cut[w[i].second] = 1;
    }
    dfs2(1, 1);
    cout << sol << '\n';
  }
}
