#include <bits/stdc++.h>
const int N = 5005;
const int INF = 0x3f3f3f3f;
using namespace std;
int T, n, m, head[N], cnte, sz[N], w[N], b[N];
struct edge {
  int to, nxt;
} e[N << 1];
pair<int, int> f[N][N];
template <typename T>
inline T read() {
  T x = 0, w = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') w = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * w;
}
inline void adde(int u, int v) {
  e[++cnte] = (edge){v, head[u]}, head[u] = cnte;
}
void dfs(int u, int fa) {
  sz[u] = 1, f[u][1].first = 0, f[u][1].second = w[u] - b[u];
  for (int v, x, i = head[u]; i; i = e[i].nxt) {
    v = e[i].to;
    if (v == fa) continue;
    dfs(v, u);
    for (int j = sz[u]; j; j--)
      for (int k = sz[v]; k; k--) {
        if (j + k <= m) {
          x = f[u][j].first + f[v][k].first + (f[v][k].second > 0);
          if (x == f[u][j + k].first)
            f[u][j + k].second = max(f[u][j + k].second, f[u][j].second);
          else if (x > f[u][j + k].first)
            f[u][j + k].first = x, f[u][j + k].second = f[u][j].second;
        }
        if (j + k - 1 <= m) {
          x = f[u][j].first + f[v][k].first;
          if (k == 1)
            f[u][j + k - 1].first += f[v][k].first,
                f[u][j + k - 1].second += f[v][k].second;
          else {
            if (x == f[u][j + k - 1].first)
              f[u][j + k - 1].second =
                  max(f[u][j + k - 1].second, f[u][j].second + f[v][k].second);
            else if (x > f[u][j + k - 1].first)
              f[u][j + k - 1].first = x, f[u][j + k - 1].second =
                                             f[u][j].second + f[v][k].second;
          }
        }
      }
    sz[u] += sz[v];
  }
}
int main() {
  T = read<int>();
  while (T--) {
    n = read<int>(), m = read<int>();
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) f[i][j].first = 0, f[i][j].second = -INF;
    cnte = 0;
    for (int i = 1; i <= n; i++) head[i] = 0;
    for (int i = 1; i <= n; i++) b[i] = read<int>();
    for (int i = 1; i <= n; i++) w[i] = read<int>();
    for (int u, v, i = 1; i < n; i++) {
      u = read<int>(), v = read<int>();
      adde(u, v), adde(v, u);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
  }
  return 0;
}
