#include <bits/stdc++.h>
using namespace std;
const int N = 3001;
const long long inf = 1e18;
pair<long long, long long> dp[N][N], inner[N];
int n, m;
vector<int> g[N];
int a[N];
int sub[N];
pair<long long, long long> Merge(pair<long long, long long> a,
                                 pair<long long, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
void dfs(int u, int p) {
  sub[u] = 1;
  for (int i = 1; i <= m; i++) dp[u][i] = make_pair(-inf, -inf);
  dp[u][0] = make_pair(0, a[u]);
  for (int v : g[u]) {
    if (v == p) continue;
    dfs(v, u);
    for (int i = min(sub[v], m); i >= 1; i--) {
      pair<long long, long long> z = dp[v][i - 1];
      if (z.second > 0) z.first++;
      z.second = 0;
      dp[v][i] = max(dp[v][i], z);
    }
    for (int i = 0; i < sub[u] + sub[v] && i < m; i++) {
      inner[i] = make_pair(-inf, -inf);
    }
    for (int i = 0; i < sub[u] && i < m; i++) {
      for (int j = 0; j <= sub[v] && i + j < m; j++) {
        inner[i + j] = max(inner[i + j], Merge(dp[u][i], dp[v][j]));
      }
    }
    for (int i = 0; i < sub[u] + sub[v] && i < m; i++) {
      dp[u][i] = inner[i];
    }
    sub[u] += sub[v];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      a[i] = x - a[i];
    }
    for (int i = 1; i <= n; i++) g[i].clear();
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, -1);
    pair<long long, long long> ans = dp[1][m - 1];
    if (ans.second > 0) ans.first++;
    cout << ans.first << endl;
  }
  return 0;
}
