#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10;
int tot, n, m, si[N], a[N], b[N], head[N], nex[N << 1], to[N << 1];
void add(int u, int v) {
  to[++tot] = v;
  nex[tot] = head[u];
  head[u] = tot;
}
pair<int, int> dp[N][N], f[N];
void dfs(int u, int p) {
  si[u] = 1;
  if (b[u] > 0)
    dp[u][1] = {1, b[u]};
  else
    dp[u][1] = {0, b[u]};
  for (int i = head[u]; i; i = nex[i]) {
    int v = to[i];
    if (v == p) continue;
    dfs(v, u);
    for (int j = 1; j <= si[u] + si[v]; j++) f[j] = {0, -0x3f3f3f3f};
    for (int j = si[u]; j >= 1; j--) {
      for (int k = si[v]; k >= 1; k--) {
        f[j + k] =
            max(f[j + k], {dp[u][j].first + dp[v][k].first, dp[u][j].second});
        f[j + k - 1] =
            max(f[j + k - 1],
                {dp[u][j].first + dp[v][k].first +
                     (dp[u][j].second > 0 && dp[v][k].second > 0 ? -1 : 0) +
                     (dp[u][j].second + dp[v][k].second <= 0 &&
                              (dp[u][j].second > 0 || dp[v][k].second > 0)
                          ? -1
                          : 0),
                 dp[u][j].second + dp[v][k].second});
      }
    }
    b[u] += b[v];
    si[u] += si[v];
    for (int j = 1; j <= si[u]; j++) dp[u][j] = f[j];
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    tot = 0;
    memset(head, 0, sizeof(head));
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]), b[i] -= a[i];
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v);
      add(v, u);
    }
    memset(dp, 0, sizeof(dp));
    dfs(1, 0);
    printf("%d\n", dp[1][m].first);
  }
}
