#include <bits/stdc++.h>
long long int const MOD = 1000000007;
long long int const N = 1000005;
long long int const LN = 20;
long long int const inf = 1e18;
using namespace std;
pair<long long int, long long int> dp[3005][3005];
long long int sz[N];
long long int n, m;
long long int val[N];
vector<long long int> v[N];
pair<long long int, long long int> operator+(
    const pair<long long int, long long int> p,
    const pair<long long int, long long int> q) {
  return {p.first + q.first, p.second + q.second};
}
void dfs(long long int u, long long int p) {
  sz[u] = 1;
  dp[u][0] = {0, val[u]};
  for (auto w : v[u]) {
    if (w == p) {
      continue;
    }
    dfs(w, u);
    vector<pair<long long int, long long int> > temp;
    temp.resize(sz[w] + sz[u] + 1);
    for (long long int i = 0; i <= sz[w] + sz[u]; i++) {
      temp[i] = {-1, -1};
    }
    for (long long int i = 0; i <= sz[u]; i++) {
      for (long long int j = 0; j <= sz[w]; j++) {
        temp[i + j] = max(temp[i + j], dp[u][i] + dp[w][j]);
      }
    }
    sz[u] += sz[w];
    for (long long int i = 0; i <= sz[u]; i++) {
      dp[u][i] = temp[i];
    }
  }
  for (long long int i = sz[u] - 1; i >= 0; i--) {
    if (dp[u][i].second > 0)
      dp[u][i + 1] = max(dp[u][i + 1], {dp[u][i].first + 1, 0LL});
    else
      dp[u][i + 1] = max(dp[u][i + 1], {dp[u][i].first, 0LL});
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long int i = 0; i <= n; i++) {
      v[i].clear();
      for (long long int j = 0; j <= n; j++) dp[i][j] = {-1, -1};
    }
    for (long long int i = 1; i <= n; i++) {
      long long int d;
      cin >> d;
      val[i] -= d;
    }
    for (long long int i = 1; i <= n; i++) {
      long long int d;
      cin >> d;
      val[i] += d;
    }
    for (long long int i = 1; i < n; i++) {
      long long int a, b;
      cin >> a >> b;
      v[a].push_back(b);
      v[b].push_back(a);
    }
    dfs(1, 0);
    if (dp[1][m - 1].second > 0) {
      dp[1][m - 1].first++;
    }
    cout << dp[1][m - 1].first << '\n';
    for (long long int i = 0; i <= n; i++) {
      v[i].clear();
      val[i] = 0;
      sz[i] = 0;
      for (long long int j = 0; j <= n; j++) dp[i][j] = {-1, -1};
    }
  }
  return 0;
}
