#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int MAXN = 3010, LOG = 20;
long long n, m, k, u, v, x, y, t, a, b, ans;
long long A[MAXN];
int sz[MAXN];
pair<long long, long long> dp[MAXN][MAXN];
pair<long long, long long> dpp[MAXN];
vector<int> G[MAXN];
void dfs(int node, int par) {
  sz[node] = 1;
  dp[node][0] = {0, A[node]};
  for (int v : G[node])
    if (v != par) {
      dfs(v, node);
      for (int i = 0; i < sz[node]; i++)
        dpp[i] = dp[node][i], dp[node][i] = {0, -INF};
      for (int i = 0; i < sz[node]; i++)
        for (int j = 0; j < sz[v]; j++) {
          dp[node][i + j] = max(
              dp[node][i + j],
              {dpp[i].first + dp[v][j].first, dpp[i].second + dp[v][j].second});
          dp[node][i + j + 1] =
              max(dp[node][i + j + 1],
                  {dpp[i].first + dp[v][j].first + (dp[v][j].second > 0),
                   dpp[i].second});
        }
      sz[node] += sz[v];
    }
}
void solve() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++)
    for (int j = 0; j < m; j++) dp[i][j] = {0, -INF};
  for (int i = 1; i <= n; i++) cin >> A[i];
  for (int i = 1; i <= n; i++) cin >> x, A[i] = x - A[i], G[i].clear();
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  dfs(1, 1);
  cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
