#include <bits/stdc++.h>
using namespace std;
const int N = 4e3 + 7;
int head[N], cnt;
struct node {
  int ne, to, w;
} edg[N * 2 + 1];
void build(int u, int v) {
  ++cnt;
  edg[cnt].to = v;
  edg[cnt].ne = head[u];
  head[u] = cnt;
}
int T, n, m, sz[N];
long long w[N], b[N];
pair<long long, long long> f[N][N], g[N];
void dfs(int i, int F) {
  f[i][1] = make_pair(w[i] > 0, w[i]);
  sz[i] = 1;
  for (int tmp = head[i]; tmp; tmp = edg[tmp].ne) {
    int v = edg[tmp].to;
    if (v == F) continue;
    dfs(v, i);
    for (int j = 1; j <= min(sz[i] + sz[v], m); j++) g[j] = make_pair(0, 0);
    for (int j = 1; j <= min(m + 1, sz[i]); j++)
      for (int k = 1; k <= min(m + 1 - j, sz[v]); k++) {
        if (j + k <= m)
          g[j + k] = max(g[j + k], make_pair(f[i][j].first + f[v][k].first,
                                             f[i][j].second));
        g[j + k - 1] = max(g[j + k - 1],
                           make_pair(f[i][j].first + f[v][k].first -
                                         (f[i][j].second + f[v][k].second <= 0),
                                     f[i][j].second + f[v][k].second));
      }
    for (int j = 1; j <= min(sz[i] + sz[v], m); j++) f[i][j] = g[j];
    sz[i] += sz[v];
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    for (int i = 1; i <= n; i++) head[i] = 0;
    cnt = 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 - 1; i++) {
      int u, v, w;
      scanf("%d%d", &u, &v);
      build(u, v);
      build(v, u);
    }
    dfs(1, 0);
    printf("%lld\n", f[1][m].first);
  }
}
