#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
#pragma GCC diagnostic ignored "-Wsign-compare"
vector<long long> b;
vector<long long> w;
vector<vector<long long> > adj;
long long n, m;
vector<vector<pair<long long, long long> > > dp;
pair<long long, long long> mx(pair<long long, long long> a,
                              pair<long long, long long> b) {
  if (a.first > b.first) return a;
  if (b.first > a.first) return b;
  if (a.second > b.second) return a;
  return b;
}
void comb(vector<pair<long long, long long> >& a,
          vector<pair<long long, long long> >& b) {
  vector<pair<long long, long long> > ret(
      (long long)(a).size() + (long long)(b).size(), make_pair(-1, 0));
  for (long long i = 0; i < (long long)(a).size(); i++) {
    for (long long j = 0; j < (long long)(b).size(); j++) {
      ret[i + j] = mx(ret[i + j], make_pair(a[i].first + b[j].first,
                                            a[i].second + b[j].second));
      ret[i + j + 1] =
          mx(ret[i + j + 1],
             make_pair(a[i].first + b[j].first + (long long)(b[j].second > 0),
                       a[i].second));
    }
  }
  a = ret;
}
void dfs(long long u, long long v) {
  42;
  dp[u].push_back(make_pair(0, w[u] - b[u]));
  for (auto& first : adj[u]) {
    if (first == v) continue;
    dfs(first, u);
    comb(dp[u], dp[first]);
  }
}
void init() {
  b.clear();
  w.clear();
  adj.clear();
  dp.clear();
  b.resize(n);
  w.resize(n);
  adj.resize(n);
  dp.resize(n);
}
void pr(vector<vector<pair<long long, long long> > >& a) {
  42;
  for (long long i = 0; i < (long long)(a).size(); i++) {
    42;
  }
}
void pr(vector<vector<long long> >& a) {
  42;
  for (long long i = 0; i < (long long)(a).size(); i++) {
    42;
  }
}
void solve() {
  cin >> n >> m;
  init();
  for (long long i = 0; i < n; i++) {
    cin >> b[i];
  }
  for (long long i = 0; i < n; i++) {
    cin >> w[i];
  }
  42;
  42;
  for (long long i = 0; i < n - 1; i++) {
    long long u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  pr(adj);
  dfs(0, -1);
  cout << dp[0][m - 1].first + (long long)(dp[0][m - 1].second > 0) << '\n';
  pr(dp);
}
int32_t main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
