#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  return x * f;
}
const int INF = 2147483600;
const int MAXN = 100010;
int N, T, M;
int Node[MAXN << 1], Next[MAXN << 1], Root[MAXN + 1], cnt;
inline void insert(int u, int v) {
  Node[++cnt] = v;
  Next[cnt] = Root[u];
  Root[u] = cnt;
}
pair<int, int> f[3010][3010];
int sz[MAXN + 1];
long long val[MAXN + 1];
inline void dp(int k, int Fa) {
  for (int i = 0; i <= M; i++) f[k][i] = make_pair(-INF, 0);
  sz[k] = 1;
  f[k][0] = make_pair(0, val[k]);
  for (int x = Root[k]; x; x = Next[x]) {
    int v = Node[x];
    if (v == Fa) continue;
    dp(v, k);
    for (int i = sz[k] + sz[v]; i >= 0; i--) {
      pair<int, int> tmp = make_pair(-INF, -INF);
      for (int j = 0; j <= sz[v] && j <= i; j++) {
        if (f[k][i - j].first + f[v][j].first > tmp.first ||
            (f[k][i - j].first + f[v][j].first == tmp.first &&
             f[k][i - j].second + f[v][j].second > tmp.second))
          tmp = make_pair(f[k][i - j].first + f[v][j].first,
                          f[k][i - j].second + f[v][j].second);
      }
      f[k][i] = tmp;
    }
    sz[k] += sz[v];
  }
  if (Fa)
    for (int i = sz[k]; i >= 0; i--) {
      int now = f[k][i].first + (f[k][i].second > 0);
      if (f[k][i + 1].first < now ||
          (f[k][i + 1].first == now && f[k][i + 1].second < 0))
        f[k][i + 1] = make_pair(now, 0);
    }
}
int main() {
  T = read();
  while (T--) {
    N = read();
    M = read();
    cnt = 0;
    for (int i = 1; i <= N; i++) val[i] = -read();
    for (int i = 1; i <= N; i++) val[i] += read();
    for (int i = 1; i <= N; i++) Root[i] = 0;
    for (int i = 1; i < N; i++) {
      int u = read(), v = read();
      insert(u, v);
      insert(v, u);
    }
    dp(1, 0);
    printf("%d\n", f[1][M - 1].first + (f[1][M - 1].second > 0));
  }
  return 0;
}
