#include <bits/stdc++.h>
using namespace std;
mt19937 mrand(random_device{}());
const long long mod = 1000000007;
int rnd(int x) { return mrand() % x; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 3010;
pair<int, long long> dp[N][N], tmp[N];
int b[N], w;
vector<int> e[N];
int sz[N], _, n, m, u, v;
void dfs(int u, int f) {
  sz[u] = 1;
  dp[u][0] = make_pair(0, b[u]);
  for (auto v : e[u]) {
    if (v == f) continue;
    dfs(v, u);
    for (int i = 0; i < sz[u] + sz[v]; i++) tmp[i] = make_pair(-1, -1);
    for (int i = 0; i < sz[u]; i++)
      for (int j = 0; j <= sz[v]; j++) {
        tmp[i + j] =
            max(tmp[i + j], make_pair(dp[u][i].first + dp[v][j].first,
                                      dp[u][i].second + dp[v][j].second));
      }
    for (int i = 0; i < sz[u] + sz[v]; i++) dp[u][i] = tmp[i];
    sz[u] += sz[v];
  }
  for (int i = sz[u] - 1; i >= 0; i--) {
    auto x = dp[u][i];
    if (x.second > 0) x.first++;
    x.second = 0;
    dp[u][i + 1] = max(dp[u][i + 1], x);
  }
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i < n + 1; i++) scanf("%d", b + i);
  for (int i = 1; i < n + 1; i++) {
    scanf("%d", &w);
    b[i] = w - b[i];
  }
  for (int i = 1; i < n + 1; i++) e[i].clear();
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &u, &v);
    e[u].push_back(v);
    e[v].push_back(u);
  }
  dfs(1, 0);
  auto x = dp[1][m - 1];
  if (x.second > 0) x.first++;
  x.second = 0;
  printf("%d\n", x.first);
}
int main() {
  for (scanf("%d", &_); _; _--) {
    solve();
  }
}
