#include <bits/stdc++.h>
using namespace std;
vector<long long> vr[3005];
long long t, n, m, wr[3005], br[3005], sr[3005];
pair<long long, long long> dp[3005][3005], dp2[3005][3005];
pair<long long, long long> func(long long, long long, long long, long long,
                                long long);
vector<pair<long long, long long> > dfs(long long, long long);
pair<long long, long long> gre(pair<long long, long long> a,
                               pair<long long, long long> b) {
  if (a.first == b.first) return (a.second > b.second ? a : b);
  if (a.first < b.first) return b;
  return a;
}
int main() {
  scanf("%lld", &t);
  pair<long long, long long> neg = make_pair(-1e18, -1e18);
  for (int i = 0; i < 3005; i++)
    for (int j = 0; j < 3005; j++) dp[i][j] = dp2[i][j] = neg;
  while (t--) {
    scanf("%lld %lld", &n, &m);
    for (int i = 0; i < n + 1; i++) {
      vr[i].clear();
    }
    for (int i = 1; i < n + 1; i++) scanf("%lld", &br[i]);
    for (int i = 1; i < n + 1; i++) scanf("%lld", &wr[i]);
    for (int i = 1; i < n; i++) {
      long long x, y;
      scanf("%lld %lld", &x, &y);
      vr[x].push_back(y);
      vr[y].push_back(x);
    }
    vector<pair<long long, long long> > xr = dfs(1, 0);
    printf("%lld\n", xr[m - 1].first + (xr[m - 1].second > 0));
  }
}
vector<pair<long long, long long> > dfs(long long idx, long long p) {
  long long diff = wr[idx] - br[idx];
  vector<pair<long long, long long> > f = {{0, diff}};
  for (auto x : vr[idx]) {
    if (x == p) continue;
    vector<pair<long long, long long> > s = dfs(x, idx);
    vector<pair<long long, long long> > newf(f.size() + s.size(),
                                             {-1e18, -1e18});
    for (int j = 0; j < f.size(); j++)
      for (int k = 0; k < s.size(); k++) {
        pair<long long, long long> a = f[j], b = s[k];
        newf[j + k] =
            gre(newf[j + k], make_pair(a.first + b.first, a.second + b.second));
        newf[j + k + 1] =
            gre(newf[j + k + 1],
                make_pair(a.first + b.first + (b.second > 0), a.second));
      }
    f = newf;
  }
  return f;
}
