#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
pair<long long, long long> f[maxn][maxn], g[maxn];
int sz[maxn];
vector<int> G[maxn];
int n, m, T;
int a[maxn];
void dfs(int u, int fa) {
  sz[u] = 1;
  for (int i = 0; i <= n; i++) {
    f[u][i] = pair<long long, long long>(-1e9, -1e9);
  }
  f[u][0] = pair<long long, long long>(0, a[u]);
  for (auto v : G[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 0; i <= sz[u] + sz[v] + 1; i++) {
      g[i] = pair<long long, long long>(-1e9, -1e9);
    }
    for (int i = sz[u]; i >= 0; i--) {
      for (int j = sz[v]; j >= 0; j--) {
        g[i + j] = max(g[i + j], pair<long long, long long>(
                                     f[u][i].first + f[v][j].first,
                                     f[u][i].second + f[v][j].second));
        g[i + j + 1] = max(g[i + j + 1], pair<long long, long long>(
                                             f[u][i].first + f[v][j].first +
                                                 (f[v][j].second > 0),
                                             f[u][i].second));
      }
    }
    for (int i = 0; i <= sz[u] + sz[v] + 1; i++) {
      f[u][i] = g[i];
    }
    sz[u] += sz[v];
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      G[i].clear();
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      int x;
      cin >> x;
      a[i] = x - a[i];
    }
    for (int i = 1; i < n; ++i) {
      int u, v;
      cin >> u >> v;
      G[u].emplace_back(v);
      G[v].emplace_back(u);
    }
    dfs(1, 0);
    cout << f[1][m - 1].first + (f[1][m - 1].second > 0) << "\n";
  }
  return 0;
}
