#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3000;
int TC, N, K;
long long A[MAXN + 10];
vector<int> adj[MAXN + 10];
int sz[MAXN + 10];
pair<long long, long long> dp[MAXN + 10][MAXN + 10], tmp[MAXN + 10];
void dfs(int now, int bef) {
  int i, j;
  sz[now] = 1;
  dp[now][1] = pair<long long, long long>(0, A[now]);
  for (int nxt : adj[now]) {
    if (nxt == bef) continue;
    dfs(nxt, now);
    for (i = 1; i <= sz[now] + sz[nxt]; i++)
      tmp[i] = pair<long long, long long>(0, -1e15);
    for (i = 1; i <= sz[now]; i++) {
      for (j = 1; j <= sz[nxt]; j++) {
        tmp[i + j - 1] = max(
            tmp[i + j - 1],
            pair<long long, long long>(dp[now][i].first + dp[nxt][j].first,
                                       dp[now][i].second + dp[nxt][j].second));
        tmp[i + j] = max(tmp[i + j], pair<long long, long long>(
                                         dp[now][i].first + dp[nxt][j].first +
                                             (dp[nxt][j].second > 0),
                                         dp[now][i].second));
      }
    }
    for (i = 1; i <= sz[now] + sz[nxt]; i++) dp[now][i] = tmp[i];
    sz[now] += sz[nxt];
  }
}
int main() {
  int i, j;
  scanf("%d", &TC);
  while (TC--) {
    scanf("%d%d", &N, &K);
    for (i = 1; i <= N; i++) adj[i].clear(), A[i] = 0;
    for (i = 1; i <= N; i++) {
      long long t;
      scanf("%lld", &t);
      A[i] -= t;
    }
    for (i = 1; i <= N; i++) {
      long long t;
      scanf("%lld", &t);
      A[i] += t;
    }
    for (i = 1; i < N; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    for (i = 1; i <= N; i++)
      for (j = 1; j <= N; j++) dp[i][j] = pair<long long, long long>(0, -1e15);
    dfs(1, 1);
    printf("%lld\n", dp[1][K].first + (dp[1][K].second > 0));
  }
}
