#include <bits/stdc++.h>
using namespace std;
long long n, m;
vector<vector<long long>> g;
vector<vector<pair<long long, long long>>> dp;
pair<long long, long long> add(pair<long long, long long> a,
                               pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
vector<pair<long long, long long>> merge(
    vector<pair<long long, long long>> &a,
    vector<pair<long long, long long>> &b) {
  vector<pair<long long, long long>> ret(
      min((long long)(a.size() + b.size()), m), {-1, 0});
  for (long long i = 0; i < (long long)a.size(); ++i) {
    for (long long j = 0; j < (long long)b.size() && i + j < m; ++j) {
      ret[i + j] = max(ret[i + j], add(a[i], b[j]));
      if (i + j + 1 < m)
        ret[i + j + 1] =
            max(ret[i + j + 1], add(a[i], {b[j].first + (b[j].second > 0), 0}));
    }
  }
  return ret;
}
void dfs(long long x, long long par = 0) {
  for (auto v : g[x]) {
    if (v == par) continue;
    dfs(v, x);
    dp[x] = merge(dp[x], dp[v]);
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    cin >> n >> m;
    g.assign(n, vector<long long>());
    dp.assign(n, vector<pair<long long, long long>>());
    for (long long i = 0; i < n; ++i) {
      long long b;
      cin >> b;
      dp[i].emplace_back(0, -b);
    }
    for (long long i = 0; i < n; ++i) {
      long long w;
      cin >> w;
      dp[i][0].second += w;
    }
    for (long long i = 1; i < n; ++i) {
      long long u, v;
      cin >> u >> v;
      --u;
      --v;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(0);
    if (dp[0][m - 1].second > 0) dp[0][m - 1].first++;
    cout << dp[0][m - 1].first << '\n';
  }
}
