#include <bits/stdc++.h>
using namespace std;
int m, n;
void ckmax(array<long long, 3> &p1, array<long long, 3> p2) {
  p1 = max(p1, p2);
}
vector<array<long long, 3>> dfs(int v, int p, vector<long long> &val,
                                vector<vector<int>> &adj) {
  vector<array<long long, 3>> res(1, {-1, -1, -1});
  res[0] = {0, 0, val[v]};
  for (int e : adj[v]) {
    if (e != p) {
      auto res2 = dfs(e, v, val, adj);
      vector<array<long long, 3>> ans(res.size() + res2.size(), {-1, -1, -1});
      for (auto a1 : res) {
        if (a1[0] == -1) continue;
        for (auto a2 : res2) {
          if (a2[0] == -1) continue;
          if (a1[0] + a2[0] <= m) {
            ckmax(ans[a1[0] + a2[0]],
                  {a1[0] + a2[0], a1[1] + a2[1], a1[2] + a2[2]});
          }
          if (a1[0] + a2[0] + 1 <= m) {
            ckmax(ans[a1[0] + a2[0] + 1],
                  {a1[0] + a2[0] + 1, a1[1] + a2[1] + (a2[2] > 0), a1[2]});
          }
        }
      }
      res = ans;
    }
  }
  return res;
}
void solve() {
  cin >> n >> m;
  vector<long long> val;
  vector<vector<int>> adj(n);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    val.push_back(x);
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    val[i] = x - val[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  auto res = dfs(0, 0, val, adj);
  cout << res[m - 1][1] + (res[m - 1][2] > 0) << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
