#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4000;
const long long oo = 1e12;
int n, m;
long long a[MAXN];
vector<int> adj[MAXN];
pair<int, long long> f[MAXN][MAXN];
int sz[MAXN];
void init() {
  for (int i = 0; i <= n; i++) {
    adj[i].clear();
    a[i] = 0;
    sz[i] = 0;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j <= m; j++) f[i][j] = make_pair(0, -oo);
}
bool compare(pair<int, long long> x, pair<int, long long> y) {
  if (x.first > y.first) return true;
  if (x.first == y.first && x.second > y.second) return true;
  return false;
}
void merge(int u, int v) {
  vector<pair<int, long long> > temp(min(sz[u] + sz[v], m) + 10);
  for (int i = 0; i <= min(m, sz[u] + sz[v]); i++) temp[i] = make_pair(0, -oo);
  for (int i = 0; i <= min(m, sz[u]); i++)
    for (int j = 0; j <= min(m, sz[v]); j++)
      if (i + j > m)
        break;
      else {
        pair<int, long long> val = make_pair(f[u][i].first + f[v][j].first,
                                             f[u][i].second + f[v][j].second);
        if (compare(val, temp[i + j])) temp[i + j] = val;
      }
  for (int i = 0; i < min(m, sz[u] + sz[v]); i++) f[u][i] = temp[i];
}
void dfs(int node, int last) {
  f[node][0] = make_pair(0, a[node]);
  sz[node] = 1;
  for (int v : adj[node])
    if (v != last) {
      dfs(v, node);
      merge(node, v);
      sz[node] += sz[v];
    }
  for (int i = min(sz[node], m); i > 0; i--) {
    pair<int, long long> val;
    if (f[node][i - 1].second > 0)
      val = make_pair(f[node][i - 1].first + 1, (long long)0);
    else
      val = make_pair(f[node][i - 1].first, (long long)0);
    if (compare(val, f[node][i])) f[node][i] = val;
  }
}
int solve() {
  cin >> n >> m;
  init();
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    int temp;
    cin >> temp;
    a[i] = temp - a[i];
  }
  for (int i = 1; i < n; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, 0);
  pair<int, long long> val;
  if (f[1][m - 1].second > 0)
    return f[1][m - 1].first + 1;
  else
    return f[1][m - 1].first;
}
int main() {
  int test;
  cin >> test;
  for (; test > 0; test--) {
    cout << solve() << endl;
  }
  return 0;
}
