#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
const long long inf = 1e18;
long long sub[N], b[N], w[N];
vector<int> gr[N];
pair<long long, long long> dp[N][N], mx[N];
pair<long long, long long> pir(long long f, long long s) {
  pair<long long, long long> ans;
  ans.first = f;
  ans.second = s;
  return ans;
}
void dfs(int v = 1, int p = -1) {
  sub[v]++;
  dp[v][1] = {0, w[v]};
  for (auto u : gr[v]) {
    if (u != p) {
      dfs(u, v);
      for (int i = 0; i <= sub[u] + sub[v]; i++)
        mx[i].first = -inf, mx[i].second = -inf;
      for (int i = 1; i <= sub[v]; i++) {
        for (int j = 1; j <= sub[u]; j++) {
          mx[i + j] = max(mx[i + j], pir(dp[u][j].first + dp[v][i].first +
                                             (dp[u][j].second > 0),
                                         dp[v][i].second));
          mx[i + j - 1] =
              max(mx[i + j - 1], pir(dp[u][j].first + dp[v][i].first,
                                     dp[u][j].second + dp[v][i].second));
        }
      }
      for (int i = 1; i <= sub[u] + sub[v]; i++) dp[v][i] = mx[i];
      sub[v] += sub[u];
    }
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      w[i] = -b[i];
    }
    for (int i = 1; i <= n; i++) {
      long long tmp;
      cin >> tmp;
      gr[i].clear();
      w[i] += tmp;
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      gr[u].push_back(v);
      gr[v].push_back(u);
    }
    dfs();
    cout << dp[1][m].first + (dp[1][m].second > 0) << endl;
  }
  return 0;
}
