#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int N = 3005;
int fst[N], to[N << 1], nxt[N << 1], mm;
void ade(int u, int v) { to[++mm] = v, nxt[mm] = fst[u], fst[u] = mm; }
int siz[N];
pair<int, long long> f[N][N], tmp[N];
int n, m;
int w[N];
void dfs(int u, int fa) {
  siz[u] = 1;
  f[u][0] = make_pair(0, w[u]);
  for (int i = fst[u]; i; i = nxt[i]) {
    int v = to[i];
    if (v == fa) continue;
    dfs(v, u);
    for (int j = 0; j < siz[u] + siz[v]; j++) tmp[j] = make_pair(-10000, -INF);
    for (int j = 0; j < siz[v]; j++)
      for (int k = 0; k < siz[u]; k++) {
        tmp[j + k] =
            max(tmp[j + k], make_pair(f[v][j].first + f[u][k].first,
                                      f[u][k].second + f[v][j].second));
        tmp[j + k + 1] =
            max(tmp[j + k + 1],
                make_pair(f[v][j].first + f[u][k].first + (f[v][j].second > 0),
                          f[u][k].second));
      }
    siz[u] += siz[v];
    for (int j = 0; j < siz[u]; j++) f[u][j] = tmp[j];
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1, x; i <= n; i++) scanf("%d", &x), w[i] = -x;
    for (int i = 1, x; i <= n; i++) scanf("%d", &x), w[i] += x;
    for (int i = 1; i <= n; i++) fst[i] = 0;
    mm = 0;
    for (int i = 1, u, v; i < n; i++)
      scanf("%d%d", &u, &v), ade(u, v), ade(v, u);
    dfs(1, 0);
    printf("%d\n", f[1][m - 1].first + (f[1][m - 1].second > 0));
  }
}
