#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3 + 10;
long long w[2][N];
vector<long long> adj[N];
pair<long long, long long> f[N][N];
pair<long long, long long> tmpf[N];
long long n, m;
template <class T>
bool maximize(T &x, T y) {
  if (x < y) return x = y, 1;
  return 0;
}
long long DFS(long long u, long long par) {
  long long subU = 1;
  f[u][0] = {0, w[1][u] - w[0][u]};
  for (auto v : adj[u])
    if (v != par) {
      long long subV = DFS(v, u);
      for (long long i = 0; i <= subV + subU + 1; i++) tmpf[i] = {-1, 0};
      for (long long useU = 0; useU <= subU; useU++)
        for (long long useV = 0; useV <= subV; useV++) {
          pair<long long, long long> notMerge = {
              f[u][useU].first + f[v][useV].first + (f[v][useV].second > 0),
              f[u][useU].second};
          maximize(tmpf[useU + useV + 1], notMerge);
          pair<long long, long long> doMerge = {
              f[u][useU].first + f[v][useV].first,
              f[u][useU].second + f[v][useV].second};
          maximize(tmpf[useU + useV], doMerge);
        }
      for (long long i = 0; i <= subV + subU + 1; i++) f[u][i] = tmpf[i];
      subU += subV;
    }
  return subU;
}
long long solve() {
  DFS(1, -1);
  return f[1][m - 1].first + (f[1][m - 1].second > 0);
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long test;
  cin >> test;
  while (test--) {
    cin >> n >> m;
    for (long long i = 1; i <= n; i++) cin >> w[0][i];
    for (long long i = 1; i <= n; i++) cin >> w[1][i];
    for (long long i = 1; i < n; i++) {
      long long u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    cout << solve() << '\n';
    for (long long i = 1; i <= n; i++) adj[i].clear();
  }
}
