#include <bits/stdc++.h>
const long double EPS = 1e-8;
using namespace std;
const int N = 3010;
int n, m, sz[N];
long long b[N];
pair<int, long long> dp[N][N];
pair<int, long long> F[N];
vector<int> G[N];
void dfs(int u, int fa) {
  sz[u] = 1;
  dp[u][1] = pair<int, long long>(0, b[u]);
  for (int v : G[u])
    if (v != fa) {
      dfs(v, u);
      for (int i = (1); i <= (sz[u] + sz[v]); ++i) F[i] = {-1e9, -1e9};
      for (int i = (1); i <= (sz[u]); ++i)
        for (int j = (1); j <= (sz[v]); ++j) {
          F[i + j] = max(F[i + j], {dp[u][i].first + dp[v][j].first +
                                        (dp[v][j].second > 0),
                                    dp[u][i].second});
          F[i + j - 1] = max(F[i + j - 1], {dp[u][i].first + dp[v][j].first,
                                            dp[u][i].second + dp[v][j].second});
        }
      for (int i = (1); i <= (sz[u] + sz[v]); ++i) dp[u][i] = F[i];
      sz[u] += sz[v];
    }
}
int a1[N], a2[N], a3[N];
int foc();
int main() {
  srand(time(0));
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int _;
  cin >> _;
  while (_--) {
    cin >> n >> m;
    for (int i = (1); i <= (n); ++i) cin >> b[i];
    for (int i = (1); i <= (n); ++i) {
      int w;
      cin >> w;
      b[i] = w - b[i];
    }
    int u, v;
    for (int i = (1); i <= (n - 1); ++i)
      cin >> u >> v, G[u].push_back(v), G[v].push_back(u);
    dfs(1, 0);
    cout << dp[1][m].first + (dp[1][m].second > 0) << "\n";
    for (int i = (1); i <= (n); ++i)
      G[i].clear(), memset(dp[i], 0, sizeof(dp[i]));
  }
}
int C[N], tmpWN, winNum, S[N];
void dfs3(int u, int fa) {
  S[u] = b[u];
  for (int v : G[u])
    if (v != fa) {
      dfs3(v, u);
      if (!C[v]) S[u] += S[v];
    }
  if (C[u] || u == 1) tmpWN += (S[u] > 0);
}
void dfs2() {
  for (int st = 0; st < (1 << (n - 1)); ++st) {
    if (__builtin_popcount(st) == m - 1) {
      for (int i = (2); i <= (n); ++i) {
        C[i] = (st & (1 << (i - 2)));
      }
      tmpWN = 0;
      dfs3(1, 0);
      winNum = max(winNum, tmpWN);
    }
  }
}
int foc() {
  winNum = 0;
  dfs2();
  return winNum;
}
