#include <bits/stdc++.h>
using namespace std;
pair<int, long long> dp[3005][3005];
pair<int, long long> tmp[3005];
int n;
int m;
long long a[3005];
long long b[3005];
struct edge {
  int des;
  int next;
} e[3005 << 1];
int cnt;
int head[3005];
int size[3005];
void ins(int u, int v) {
  ++cnt;
  e[cnt].des = v;
  e[cnt].next = head[u];
  head[u] = cnt;
}
void dfs(int u, int f) {
  size[u] = 1;
  dp[u][1] = make_pair(0, a[u]);
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].des;
    if (v == f) continue;
    dfs(v, u);
    for (int j = 1; j <= size[u] + size[v]; ++j) tmp[j] = make_pair(-1, -1);
    for (int j = size[u]; j >= 1; --j) {
      for (int k = size[v]; k >= 1; --k) {
        tmp[j + k] =
            max(tmp[j + k], make_pair(dp[u][j].first + dp[v][k].first +
                                          (dp[v][k].second > 0 ? 1 : 0),
                                      dp[u][j].second));
        tmp[j + k - 1] =
            max(tmp[j + k - 1], make_pair(dp[u][j].first + dp[v][k].first,
                                          dp[u][j].second + dp[v][k].second));
      }
    }
    for (int j = 1; j <= size[u] + size[v]; ++j) dp[u][j] = tmp[j];
    size[u] += size[v];
  }
}
int main() {
  int cas;
  scanf("%d", &cas);
  while (cas--) {
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) dp[i][j] = make_pair(0, 0);
    for (int i = 1; i <= n; ++i) head[i] = 0;
    cnt = 0;
    for (int i = 1; i <= n; ++i) scanf("%lld", b + i);
    for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
    for (int i = 1; i <= n; ++i) a[i] -= b[i];
    for (int i = 1; i < n; ++i) {
      int u;
      int v;
      scanf("%d %d", &u, &v);
      ins(u, v);
      ins(v, u);
    }
    dfs(1, 0);
    printf("%d\n", dp[1][m].first + (dp[1][m].second > 0 ? 1 : 0));
  }
  return 0;
}
