#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using DP = pair<int, LL>;
const int N = 3005, INF = 1e8;
const LL INFLL = 1e18;
vector<vector<int>> adj;
LL w[N];
DP best[N][N];
int dfs(int u, int p) {
  best[u][1] = {w[u] > 0, w[u]};
  int sz = 1;
  for (int v : adj[u]) {
    if (v == p) continue;
    int csz = dfs(v, u);
    vector<DP> upd(sz + csz + 1, {-INF, 0});
    for (int x = sz; x >= 1; x--) {
      for (int y = csz; y >= 1; y--) {
        DP no_merge(best[u][x].first + best[v][y].first, best[u][x].second);
        upd[x + y] = max(upd[x + y], no_merge);
        DP merge(best[u][x].first + best[v][y].first,
                 best[u][x].second + best[v][y].second);
        if (best[v][y].second > 0) {
          merge.first--;
        }
        if (best[u][x].second > 0) {
          merge.first--;
        }
        if (merge.second > 0) {
          merge.first++;
        }
        upd[x + y - 1] = max(upd[x + y - 1], merge);
      }
    }
    sz += csz;
    for (int x = 1; x <= sz; x++) {
      best[u][x] = upd[x];
    }
  }
  return sz;
}
int solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    w[i] = x - w[i];
  }
  adj.assign(n + 1, vector<int>());
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 1);
  return best[1][m].first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << '\n';
  }
  return 0;
}
