#include <bits/stdc++.h>
using namespace std;
const int maxN = 3010, oo = 1e9;
vector<int> adj[maxN];
pair<int, long long> old_dp[maxN][maxN], dp[maxN][maxN];
int sz[maxN], n, m, w[maxN];
pair<int, long long> sum(pair<int, long long> A, pair<int, long long> B) {
  return pair<int, long long>(A.first + B.first, A.second + B.second);
}
void DFS(int v, int par = -1) {
  sz[v] = 1;
  old_dp[v][0] = dp[v][0] = pair<int, long long>(-oo, 0);
  old_dp[v][1] = dp[v][1] = pair<int, long long>(0, w[v]);
  for (auto u : adj[v]) {
    if (u == par) continue;
    DFS(u, v);
    for (int i = 0; i <= sz[v] + sz[u]; i++)
      dp[v][i] = pair<int, long long>(-oo, 0);
    for (int i = 1; i <= sz[v]; i++)
      for (int j = 1; j <= sz[u]; j++) {
        dp[v][i + j - 1] = max(dp[v][i + j - 1], sum(old_dp[v][i], dp[u][j]));
        dp[v][i + j] = max(
            dp[v][i + j],
            sum(old_dp[v][i], pair<int, long long>(
                                  dp[u][j].first + (dp[u][j].second > 0), 0)));
      }
    sz[v] += sz[u];
    for (int i = 1; i <= sz[v]; i++) old_dp[v][i] = dp[v][i];
  }
}
int solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) adj[i].clear();
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    w[i] = x - w[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(0);
  cout << dp[0][m].first + (dp[0][m].second > 0) << '\n';
  return 0;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
