#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 100;
const int K = 7e2 + 10;
const int inf = 1e18;
const int mod = 1e9 + 7;
int q;
int n, m;
int w[N];
vector<int> g[N];
pair<int, long long> dp[N][N];
int sub[N];
pair<int, long long> operator+(const pair<int, long long> &p1,
                               const pair<int, long long> &p2) {
  return pair<int, long long>(p1.first + p2.first, p1.second + p2.second);
}
void dfs(int v, int p) {
  dp[v][0].second = w[v];
  dp[v][0].first = 0;
  for (auto u : g[v])
    if (u != p) {
      dfs(u, v);
      vector<pair<int, long long> > buf(min(sub[v], m) + min(sub[u], m) + 2,
                                        make_pair(-1, 0));
      for (int i = 0; i <= min(sub[v], m); ++i)
        for (int j = 0; j <= min(sub[u], m); ++j) {
          buf[i + j] = max(buf[i + j], dp[v][i] + dp[u][j]);
          pair<int, long long> tmp = dp[u][j];
          if (tmp.second > 0) ++tmp.first;
          tmp.second = 0;
          buf[i + j + 1] = max(buf[i + j + 1], dp[v][i] + tmp);
        }
      for (int i = 0; i < buf.size(); ++i) dp[v][i] = buf[i];
      sub[v] += sub[u];
    }
  sub[v] += 1;
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> w[i];
  for (int i = 0; i <= n; ++i)
    for (int j = 0; j <= m + 5; ++j) dp[i][j] = make_pair(0, 0);
  for (int i = 0; i < n; ++i) sub[i] = 0;
  for (int i = 0; i < n; ++i) g[i].clear();
  for (int i = 0; i < n; ++i) {
    int tmp = 0;
    cin >> tmp;
    w[i] = -w[i] + tmp;
  }
  for (int i = 0; i < n - 1; ++i) {
    int v, u;
    cin >> v >> u;
    --v;
    --u;
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(0, -1);
  std::cout << (dp[0][m - 1].first + (dp[0][m - 1].second > 0)) << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  while (q--) solve();
}
