#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops", "omit-frame-pointer", "inline")
#pragma GCC option("arch=native", "tune=native", "no-zero-upper")
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC target("sse4")
using namespace std;
long long w[(long long)(3e3 + 5)];
int sz[(long long)(3e3 + 5)];
vector<int> g[(long long)(3e3 + 5)];
bool mk[(long long)(3e3 + 5)];
int dp0[(long long)(3e3 + 5)][(long long)(3e3 + 5)];
int dp1[(long long)(3e3 + 5)][(long long)(3e3 + 5)];
long long dp2[(long long)(3e3 + 5)][(long long)(3e3 + 5)];
int n;
void dfs(long long u) {
  mk[u] = 1;
  for (long long i = 0; i <= n; i++) {
    dp0[u][i] = dp1[u][i] = -1e9;
    dp2[u][i] = -(long long)(1e18);
  }
  dp1[u][0] = 0;
  dp2[u][0] = w[u];
  sz[u] = 1;
  for (auto v : g[u]) {
    if (mk[v]) continue;
    dfs(v);
    long long v1, v2, p1, p2;
    int mm;
    int i, j;
    for (i = sz[u] - 1 + sz[v]; i >= 0; i--) {
      p1 = -(long long)(1e18);
      p2 = -(long long)(1e18);
      mm = min(sz[v], i);
      for (j = max(0, i - sz[u] + 1); j <= mm; j++) {
        v1 = dp1[u][i - j] + dp1[v][j];
        if (v1 >= p1) {
          v2 = dp2[u][i - j] + dp2[v][j];
          if (v1 > p1 || v2 > p2) {
            p1 = v1;
            p2 = v2;
          }
        }
        v1 = dp1[u][i - j] + dp0[v][j];
        if (v1 >= p1) {
          v2 = dp2[u][i - j];
          if (v1 > p1 || v2 > p2) {
            p1 = v1;
            p2 = v2;
          }
        }
      }
      dp1[u][i] = p1;
      dp2[u][i] = p2;
    }
    sz[u] += sz[v];
  }
  for (long long i = 1; i <= sz[u]; i++)
    dp0[u][i] = dp1[u][i - 1] + (dp2[u][i - 1] > 0);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    long long m;
    cin >> n >> m;
    for (long long i = 0; i < n; i++) cin >> w[i];
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      w[i] = x - w[i];
    }
    for (long long i = 0; i < n - 1; i++) {
      long long u, v;
      cin >> u >> v;
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(0);
    cout << (dp0[0][m]) << '\n';
    for (long long i = 0; i < n; i++) {
      sz[i] = 0;
      mk[i] = 0;
      w[i] = 0;
      g[i].clear();
    }
  }
  return 0;
}
