#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const long long INF = (1e+18) + 7;
const long double eps = 1e-6;
const long double pi = acos(-1.0);
long long mod_pow(long long a, long long n) {
  long long res = 1;
  while (n) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
struct modint {
  long long n;
  modint() : n(0) { ; }
  modint(long long m) : n(m) {
    if (n >= mod)
      n %= mod;
    else if (n < 0)
      n = (n % mod + mod) % mod;
  }
  operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) {
  a.n += b.n;
  if (a.n >= mod) a.n -= mod;
  return a;
}
modint operator-=(modint &a, modint b) {
  a.n -= b.n;
  if (a.n < 0) a.n += mod;
  return a;
}
modint operator*=(modint &a, modint b) {
  a.n = ((long long)a.n * b.n) % mod;
  return a;
}
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
  if (n == 0) return modint(1);
  modint res = (a * a) ^ (n / 2);
  if (n % 2) res = res * a;
  return res;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
using lP = pair<int, long long>;
using speP = pair<vector<int>, vector<lP>>;
lP merge(lP &a, lP &b) { return {a.first + b.first, a.second + b.second}; }
void upd(speP &l) {
  int len = l.first.size() - 1;
  for (int i = 1; i <= len; i++) {
    if (l.second[i].second > 0) {
      l.first[i] = max(l.first[i], l.second[i].first + 1);
    } else {
      l.first[i] = max(l.first[i], l.second[i].first);
    }
  }
}
speP merge(speP &l, speP &r) {
  int l1 = l.first.size() - 1;
  int l2 = r.first.size() - 1;
  speP res;
  res.first.resize(l1 + l2 + 1, 0);
  res.second.resize(l1 + l2 + 1, {0, -INF});
  for (int x = 1; x <= l1; x++) {
    for (int y = 1; y <= l2; y++) {
      res.first[x + y] = max(res.first[x + y], l.first[x] + r.first[y]);
      res.second[x + y] =
          max(res.second[x + y],
              {l.second[x].first + r.first[y], l.second[x].second});
      res.second[x + y - 1] =
          max(res.second[x + y - 1], merge(l.second[x], r.second[y]));
    }
  }
  upd(res);
  return res;
}
long long b[3000], w[3000];
vector<int> G[3000];
speP dfs(int id, int fr) {
  speP res;
  res.first = {0, w[id] > b[id]};
  res.second = {{0, 0}, {0, w[id] - b[id]}};
  for (int to : G[id]) {
    if (to == fr) continue;
    speP nex = dfs(to, id);
    res = merge(res, nex);
  }
  upd(res);
  return res;
}
void solve() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < n; i++) {
    G[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  speP out = dfs(0, -1);
  int ans = out.first[k];
  cout << ans << endl;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) solve();
  char nyaa;
  cin >> nyaa;
  return 0;
}
