#include <bits/stdc++.h>
using namespace std;
int n, m, tot;
long long b[3005], w[3005];
int head[3005], nex[3005 << 1], to[3005 << 1];
void add(int x, int y) {
  to[++tot] = y;
  nex[tot] = head[x];
  head[x] = tot;
}
long long dp1[3005][3005], dp2[3005][3005];
int sz[3005];
long long temp1[3005], temp2[3005];
void dfs(int now, int fa) {
  sz[now] = 1;
  dp1[now][1] = 0;
  dp2[now][1] = w[now];
  for (int i = head[now]; i; i = nex[i]) {
    if (to[i] != fa) {
      dfs(to[i], now);
      for (int j = 0; j <= m; j++) {
        temp1[j] = -1;
        temp2[j] = 0;
      }
      for (int j = 1; j <= sz[now]; j++) {
        for (int k = 1; k <= sz[to[i]]; k++) {
          if (temp1[j + k - 1] < dp1[now][j] + dp1[to[i]][k]) {
            temp1[j + k - 1] = dp1[now][j] + dp1[to[i]][k];
            temp2[j + k - 1] = dp2[now][j] + dp2[to[i]][k];
          } else if (temp1[j + k - 1] == dp1[now][j] + dp1[to[i]][k]) {
            temp2[j + k - 1] =
                max(temp2[j + k - 1], dp2[now][j] + dp2[to[i]][k]);
          }
          if (temp1[j + k] <
              dp1[now][j] + (dp1[to[i]][k] + (dp2[to[i]][k] > 0))) {
            temp1[j + k] = dp1[now][j] + (dp1[to[i]][k] + (dp2[to[i]][k] > 0));
            temp2[j + k] = dp2[now][j];
          } else if (temp1[j + k] ==
                     dp1[now][j] + (dp1[to[i]][k] + (dp2[to[i]][k] > 0))) {
            temp2[j + k] = max(temp2[j + k], dp2[now][j]);
          }
        }
      }
      for (int j = 0; j <= m; j++) {
        dp1[now][j] = temp1[j];
        dp2[now][j] = temp2[j];
      }
      sz[now] += sz[to[i]];
    }
  }
}
int main() {
  int _;
  scanf("%d", &_);
  while (_--) {
    tot = 0;
    for (int i = 1; i <= n; i++) {
      head[i] = 0;
      for (int j = 0; j <= m; j++) dp1[i][j] = dp2[i][j] = 0;
    }
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
    for (int i = 1; i <= n; i++) {
      scanf("%lld", &w[i]);
      w[i] -= b[i];
    }
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      add(x, y);
      add(y, x);
    }
    dfs(1, -1);
    long long ans = dp1[1][m];
    if (dp2[1][m] > 0) ans++;
    printf("%lld\n", ans);
  }
}
