#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long n;
vector<int> G[3002];
long long b[3002], w[3002];
long long siz[3002];
pair<long long, long long> dp[3002][3002];
long long dfs(long long v, long long p) {
  siz[v] = 1;
  dp[v][0] = pair<long long, long long>(0, w[v] - b[v]);
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] == p) continue;
    int ch = dfs(G[v][i], v);
    for (int j = siz[v]; j < siz[v] + ch; j++) {
      dp[v][j] = pair<long long, long long>(0, 0);
    }
    for (int j = 0; j < ch; j++) {
      dp[v][siz[v]] = pair<long long, long long>(0, 0);
      for (int k = min(siz[v] - 1, siz[v] - j); k >= 0; k--) {
        if (k + j <= siz[v]) {
          pair<long long, long long> q = dp[v][k];
          q.first += dp[G[v][i]][j].first;
          q.second += dp[G[v][i]][j].second;
          dp[v][k + j] = max(dp[v][k + j], q);
        }
        if (k + j + 1 <= siz[v]) {
          pair<long long, long long> q = dp[v][k];
          q.first += dp[G[v][i]][j].first;
          if (dp[G[v][i]][j].second > 0) q.first++;
          dp[v][k + j + 1] = max(dp[v][k + j + 1], q);
        }
      }
      siz[v]++;
    }
  }
  return siz[v];
}
int main() {
  int t;
  scanf("%d", &t);
  for (; t > 0; t--) {
    long long m;
    scanf("%lld%lld", &n, &m);
    for (int i = 0; i < n; i++) {
      scanf("%lld", &b[i]);
    }
    for (int i = 0; i < n; i++) {
      scanf("%lld", &w[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      long long a, b;
      scanf("%lld%lld", &a, &b);
      G[a].push_back(b);
      G[b].push_back(a);
    }
    dfs(1, 0);
    long long ret = dp[1][m - 1].first;
    if (dp[1][m - 1].second > 0) ret++;
    printf("%lld\n", ret);
    for (int i = 1; i <= n; i++) {
      G[i].clear();
    }
  }
}
