#include <bits/stdc++.h>
using namespace std;
const int inf = 2e9;
const long long INF = 8e18;
const int maxn = 3e3 + 5;
int n, m;
int a[maxn], sz[maxn];
pair<int, long long> dp[maxn][maxn], dpp[maxn][maxn];
vector<int> e[maxn];
inline void init() {
  for (int i = 0; i < n + 5; ++i) e[i].clear();
}
inline void dfs(int u, int pre) {
  sz[u] = 1;
  dp[u][1] = {0, a[u]};
  for (auto v : e[u]) {
    if (v == pre) continue;
    dfs(v, u);
    for (int i = 1; i <= sz[u] + sz[v]; ++i) dpp[u][i] = {0, -INF};
    for (int i = 1; i <= sz[u]; ++i) {
      for (int j = 1; j <= sz[v]; ++j) {
        dpp[u][i + j] = max(dpp[u][i + j], {dp[u][i].first + dp[v][j].first +
                                                (dp[v][j].second > 0),
                                            dp[u][i].second});
        dpp[u][i + j - 1] =
            max(dpp[u][i + j - 1], {dp[u][i].first + dp[v][j].first,
                                    dp[v][j].second + dp[u][i].second});
      }
    }
    for (int i = 1; i <= sz[u] + sz[v]; ++i) dp[u][i] = dpp[u][i];
    sz[u] += sz[v];
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    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 = 0; i < n - 1; ++i) {
      int u, v;
      cin >> u >> v;
      e[u].push_back(v);
      e[v].push_back(u);
    }
    dfs(1, 1);
    cout << dp[1][m].first + (dp[1][m].second > 0) << '\n';
    init();
  }
  return 0;
}
