#include <bits/stdc++.h>
% : pragma GCC optimize "-O3" % : pragma GCC optimize("Ofast") %
    : pragma GCC optimize("inline") % : pragma GCC optimize("fast-math") %
    : pragma GCC optimize("unroll-loops") %
    : pragma GCC optimize("inline-functions") %
    : pragma GCC optimize("no-stack-protector") %
    : pragma GCC optimize("inline-small-functions") %
    : pragma GCC optimize("inline-functions-called-once") %
    : pragma GCC target("sse3", "sse2", "sse") using namespace std;
const long long maxn = 3000 + 5, inf = 9e17;
pair<long long, long long> dp[maxn][maxn], tmp[maxn];
vector<long long> adj[maxn];
long long siz[maxn], a[maxn], t, n, m, w;
inline void dfs(long long u, long long fa) {
  siz[u] = 1;
  dp[u][1] = make_pair(0, a[u]);
  for (auto v : adj[u]) {
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
    for (int j = 0; j <= siz[u]; j++) tmp[j] = make_pair(-inf, 0);
    for (int j = 1; j <= siz[u]; j++)
      for (int k = 1; k <= siz[v]; k++) {
        tmp[j + k] = max(tmp[j + k], make_pair(dp[u][j].first + dp[v][k].first +
                                                   (dp[v][k].second > 0),
                                               dp[u][j].second));
        tmp[j + k - 1] =
            max(tmp[j + k - 1], make_pair(dp[u][j].first + dp[v][k].first,
                                          dp[u][j].second + dp[v][k].second));
      }
    for (int j = 1; j <= siz[u]; j++) dp[u][j] = tmp[j];
  }
  return;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr), cout.tie(nullptr);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) {
      cin >> w;
      a[i] = w - a[i];
    }
    long long u, v;
    for (int i = 1; i < n; i++) {
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(1, -1);
    cout << dp[1][m].first + (dp[1][m].second > 0) << "\n";
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      for (int j = 1; j <= m; j++) dp[i][j] = make_pair(-inf, 0);
    }
  }
  return 0;
}
