#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
mt19937 rng((unsigned)chrono::system_clock::now().time_since_epoch().count());
inline long long int MOD(long long int x, long long int m = mod) {
  long long int y = x % m;
  return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const long long int infl = LLONG_MAX;
const int nmax = 3000 + 10;
vector<int> adj[nmax];
long long int val[nmax];
int n, m;
pair<int, long long int> memo[nmax][nmax];
int vis[nmax][nmax], clk;
inline void maxself(int a, int b, pair<int, long long int> q) {
  if (vis[a][b] != clk) {
    vis[a][b] = clk;
    memo[a][b] = q;
  } else {
    memo[a][b] = max(memo[a][b], q);
  }
}
int dfs(int root, int par) {
  int ret = 0;
  memo[root][0] = make_pair(0, 0ll);
  for (int x : adj[root]) {
    if (x == par) continue;
    int tmp = dfs(x, root);
    for (int i = min(m - 1, ret); i >= 0; i--) {
      auto p = memo[root][i];
      for (int j = min(m - 1 - i, tmp - 1); j >= 0; j--) {
        auto q = memo[x][j];
        maxself(root, i + j, make_pair(p.first + q.first, p.second + q.second));
        maxself(root, i + j + 1,
                make_pair(p.first + q.first + (q.second > 0), p.second));
      }
    }
    ret += tmp;
  }
  ret++;
  for (int i = 0; i <= ret - 1; i++) memo[root][i].second += val[root];
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int tc;
  cin >> tc;
  for (int cs = 1; cs <= tc; cs++) {
    clk++;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> val[i];
      val[i] = -val[i];
    }
    for (int i = 1; i <= n; i++) {
      long long int x;
      cin >> x;
      val[i] += x;
      adj[i].clear();
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(1, -1);
    int ans = memo[1][m - 1].first + (memo[1][m - 1].second > 0);
    cout << ans << "\n";
  }
  return 0;
}
