#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
long long n, m;
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);
    }
    siz[v] += ch;
    for (int t = min(siz[v] - 1, m - 1);
         t >= max((long long)0, m + siz[v] - n - 1); t--) {
      dp[v][t].second += dp[G[v][i]][0].second;
      for (int j = max((long long)1, t + ch - siz[v] + 1); j < min(t + 1, ch);
           j++) {
        pair<long long, long long> q = dp[v][t - j];
        q.first += dp[G[v][i]][j].first;
        q.second += dp[G[v][i]][j].second;
        dp[v][t] = max(dp[v][t], q);
      }
      for (int j = max((long long)0, t + ch - siz[v]); j < min(t, ch); j++) {
        pair<long long, long long> q = dp[v][t - j - 1];
        q.first += dp[G[v][i]][j].first;
        if (dp[G[v][i]][j].second > 0) q.first++;
        dp[v][t] = max(dp[v][t], q);
      }
    }
  }
  return siz[v];
}
int main() {
  int t;
  scanf("%d", &t);
  for (; t > 0; t--) {
    scanf("%lld%lld", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &b[i]);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &w[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      long long x, y;
      scanf("%lld%lld", &x, &y);
      G[x].push_back(y);
      G[y].push_back(x);
    }
    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();
    }
  }
}
