#include <bits/stdc++.h>
using namespace std;
long long ksm(long long a, long long b) {
  if (!b) return 1;
  long long ns = ksm(a, b >> 1);
  ns = ns * ns % 998244353;
  if (b & 1) ns = ns * a % 998244353;
  return ns;
}
int w[3010], b[3010], sz[3010];
vector<int> eg[3010];
pair<int, long long> dp[3010][3010];
pair<int, long long> add(pair<int, long long> a, pair<int, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
const long long inf = 1e18;
void upd(int a) {
  dp[a][sz[a]] = make_pair(0, -inf);
  for (int i = sz[a] - 1; i >= 0; i--)
    dp[a][i + 1] = max(dp[a][i + 1],
                       make_pair(dp[a][i].first + (dp[a][i].second > 0), 0ll));
}
pair<int, long long> r[3010];
void dfs(int a, int fa) {
  dp[a][0] = make_pair(0, w[a]);
  sz[a] = 1;
  for (auto v : eg[a]) {
    if (v == fa) continue;
    dfs(v, a);
    upd(v);
    for (int i = 0; i < sz[v] + sz[a]; i++) r[i] = make_pair(0, -inf);
    for (int i = 0; i <= sz[v]; i++)
      for (int j = 0; j < sz[a]; j++)
        r[i + j] = max(r[i + j], add(dp[v][i], dp[a][j]));
    sz[a] += sz[v];
    for (int i = 0; i < sz[a]; i++) dp[a][i] = r[i];
  }
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
      eg[i].clear();
    }
    for (int i = 1; i <= n; i++) scanf("%d", &w[i]), w[i] -= b[i];
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      eg[u].push_back(v), eg[v].push_back(u);
    }
    dfs(1, 0);
    int ans = dp[1][m - 1].first + (dp[1][m - 1].second > 0);
    cout << ans << endl;
  }
  return 0;
}
