#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long N = 3030;
const long long inf = 1e18;
long long sz[N];
long long n, m;
pair<long long, long long> dp[N][N], newDP[N];
long long val[N];
vector<vector<long long>> adj;
pair<long long, long long> add(const pair<long long, long long> &x,
                               const pair<long long, long long> &y) {
  return make_pair(x.first + y.first, x.second + y.second);
}
void dfs(long long node, long long par) {
  sz[node] = 1;
  dp[node][0] = make_pair(0LL, val[node]);
  for (long long i = 1; i <= m; ++i) {
    dp[node][i] = make_pair(-inf, -inf);
  }
  for (long long to : adj[node]) {
    if (to == par) continue;
    dfs(to, node);
    for (long long i = min(m, sz[to]); i > 0; --i) {
      pair<long long, long long> temp = dp[to][i - 1];
      temp.first += (temp.second > 0);
      temp.second = 0;
      dp[to][i] = max(dp[to][i], temp);
    }
    for (long long i = 0; i <= sz[node] + sz[to] && i <= m; ++i) {
      newDP[i] = make_pair(-inf, -inf);
    }
    for (long long i = 0; i <= sz[node] + sz[to] && i <= m; ++i) {
      for (long long j = 0; j <= sz[to] && i + j <= m; ++j) {
        if (dp[node][i].first < 0 || dp[to][j].first < 0) continue;
        newDP[i + j] = max(newDP[i + j], add(dp[node][i], dp[to][j]));
      }
    }
    sz[node] += sz[to];
    for (long long i = min(m, sz[node]); i >= 0; --i) {
      dp[node][i] = newDP[i];
    }
  }
}
void solve() {
  cin >> n >> m;
  adj.clear();
  adj.resize(n + 1);
  for (long long i = 1; i <= n; ++i) {
    cin >> val[i];
  }
  for (long long i = 1; i <= n; ++i) {
    long long temp;
    cin >> temp;
    val[i] = temp - val[i];
  }
  for (long long i = 1; i < n; ++i) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 1);
  cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
