#include <bits/stdc++.h>
using namespace std;
long long M = 1e9 + 7;
const long long N = 3e3 + 7;
vector<long long> ad[N];
long long n, m;
long long a[N];
long long dp[N][N];
long long f[N][N];
long long g[N], t[N], sz[N];
void get(long long v, long long p) {
  if (a[v] > 0) dp[v][1] = 1;
  sz[v] = 1;
  f[v][1] = a[v];
  for (auto u : ad[v])
    if (u != p) {
      get(u, v);
      for (long long i = 0; i < N; i++) t[i] = -1e18;
      memset(g, 0, sizeof g);
      for (long long i = 1; i <= sz[u]; i++)
        for (long long j = 1; j <= sz[v]; j++) {
          if (g[i + j] < dp[u][i] + dp[v][j] ||
              (g[i + j] == dp[u][i] + dp[v][j] && t[i + j] < f[v][j])) {
            g[i + j] = dp[u][i] + dp[v][j];
            t[i + j] = f[v][j];
          }
          long long cnt = dp[u][i] + dp[v][j];
          if ((f[u][i] > 0 && f[v][j] > 0) ||
              (!(f[u][i] <= 0 && f[v][j] <= 0) && f[u][i] + f[v][j] <= 0))
            cnt--;
          if (g[i + j - 1] < cnt ||
              (g[i + j - 1] == cnt && t[i + j - 1] < f[u][i] + f[v][j])) {
            g[i + j - 1] = cnt;
            t[i + j - 1] = f[u][i] + f[v][j];
          }
        }
      sz[v] += sz[u];
      for (long long i = 0; i < N; i++) {
        dp[v][i] = g[i];
        f[v][i] = t[i];
      }
    }
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    ad[i].clear();
    a[i] = 0;
    memset(dp[i], 0, sizeof dp[i]);
  }
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    a[i] -= t;
  }
  for (long long i = 1; i <= n; i++) {
    long long t;
    cin >> t;
    a[i] += t;
  }
  for (long long i = 1; i < n; i++) {
    long long v, u;
    cin >> v >> u;
    ad[v].push_back(u);
    ad[u].push_back(v);
  }
  get(1, 0);
  cout << dp[1][m] << '\n';
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    solve();
  }
  return 0;
}
