#include <bits/stdc++.h>
using namespace std;
const int maxn = 3000 + 50;
struct Edge {
  int to, next;
  long long w;
} edge[maxn * 2];
int k = 1, head[maxn];
void add(int u, int v) {
  edge[++k].to = v;
  edge[k].next = head[u];
  head[u] = k;
}
long long n, m, b[maxn], w[maxn], v[maxn], sz[maxn], T;
pair<long long, long long> dp[maxn][maxn], temp[maxn];
void update(pair<long long, long long> &x, pair<long long, long long> y) {
  if (y > x) x = y;
}
void dfs(int u, int f) {
  sz[u] = 1;
  dp[u][1] = make_pair(0, v[u]);
  for (int i = head[u]; i; i = edge[i].next) {
    if (edge[i].to == f) continue;
    dfs(edge[i].to, u);
    for (int j = 1; j <= sz[u] + sz[edge[i].to]; j++)
      temp[j] = make_pair(-1, 0);
    for (int j = 1; j <= sz[u]; j++) {
      for (int k = 1; k <= sz[edge[i].to]; k++) {
        update(temp[j + k], make_pair(dp[u][j].first + dp[edge[i].to][k].first +
                                          (dp[edge[i].to][k].second > 0),
                                      dp[u][j].second));
        update(temp[j + k - 1],
               make_pair(dp[u][j].first + dp[edge[i].to][k].first,
                         dp[u][j].second + dp[edge[i].to][k].second));
      }
    }
    for (int j = 1; j <= sz[u] + sz[edge[i].to]; j++) dp[u][j] = temp[j];
    sz[u] += sz[edge[i].to];
  }
}
int main() {
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> b[i], v[i] -= b[i];
    for (int i = 1; i <= n; i++) cin >> w[i], v[i] += w[i];
    for (int i = 1; i < n; i++) {
      int a, b;
      cin >> a >> b;
      add(a, b);
      add(b, a);
    }
    dfs(1, 0);
    long long ans = dp[1][m].first + (dp[1][m].second > 0);
    cout << ans << endl;
    k = 1;
    memset(head, 0, sizeof(int) * (n + 10));
    memset(v, 0, sizeof(long long) * (n + 10));
    memset(sz, 0, sizeof(long long) * (n + 10));
  }
  return 0;
}
