#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  return x * f;
}
inline void write(long long x) {
  if (x < 0) x = -x, putchar('-');
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  putchar('\n');
}
inline void wri(long long x) {
  write(x);
  putchar(' ');
}
const int mod = 1e9 + 7;
const int maxn = 2e5 + 233;
int size[maxn], a[maxn];
pair<int, long long> f[3005][3005], g[3005];
vector<int> edge[maxn];
void dfs(int u, int fa) {
  size[u] = 1;
  f[u][1] = {0, a[u]};
  for (auto v : edge[u])
    if (v != fa) {
      dfs(v, u);
      for (int j = (0); j <= int(size[u] + size[v]); ++j) g[j] = {-1, 0};
      for (int j = (1); j <= int(size[u]); ++j) {
        for (int k = (1); k <= int(size[v]); ++k) {
          int x = f[u][j].first + f[v][k].first;
          int y = f[v][k].second;
          g[j + k - 1] = max(g[j + k - 1], {x, f[u][j].second + y});
          g[j + k] = max(g[j + k], {x + (y > 0), f[u][j].second});
        }
      }
      size[u] += size[v];
      for (int j = (1); j <= int(size[u]); ++j) f[u][j] = g[j];
    }
}
void ss(int u, int fa) { dfs(u, fa); }
int n, m;
void solve() {
  for (int i = (1); i <= int(n); ++i) edge[i].clear();
  n = read(), m = read();
  for (int i = (1); i <= int(n); ++i) a[i] = 0;
  for (int i = (1); i <= int(n); ++i) a[i] -= read();
  for (int i = (1); i <= int(n); ++i) a[i] += read();
  for (register int i = (1); i < int(n); ++i) {
    int x = read(), y = read();
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  dfs(1, 0);
  int x = f[1][m].first + (f[1][m].second > 0);
  if (x < 0)
    puts("0");
  else
    writeln(x);
}
int main() {
  int T = read();
  while (T--) solve();
  return 0;
}
