#include <bits/stdc++.h>
int solve();
int main(int argc, char* argv[]) {
  int tc = 1;
  scanf("%d", &tc);
  while (tc--) {
    solve();
  }
  return 0;
}
constexpr int MOD = 1000 * 1000 * 1000 + 7;
struct group {
  int win;
  long long adv;
  group(int win, long long adv) : win(win), adv(adv) {}
  group operator+(const group& o) const {
    return group(win + o.win, adv + o.adv);
  }
  group inc() const { return group(win + (adv > 0), 0); }
  bool operator<(const group& o) const {
    return (win < o.win) || (win == o.win && adv < o.adv);
  }
};
std::vector<group> merge(const std::vector<group>& fx,
                         const std::vector<group>& fy) {
  std::vector<group> f(fx.size() + fy.size(), group(-1, 0));
  for (int i = 0; i < fx.size(); ++i) {
    for (int j = 0; j < fy.size(); ++j) {
      f[i + j] = std::max(f[i + j], fx[i] + fy[j]);
      f[i + j + 1] = std::max(f[i + j + 1], fx[i] + fy[j].inc());
    }
  }
  return f;
}
std::vector<std::vector<int>> adj;
std::vector<std::vector<group>> f;
void traverse_tree(int x, int p = -1) {
  for (int y : adj[x]) {
    if (y != p) {
      traverse_tree(y, x);
      f[x] = merge(f[x], f[y]);
    }
  }
}
int solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  adj = std::vector<std::vector<int>>(n);
  f = std::vector<std::vector<group>>(n, std::vector<group>(1, group(0, 0)));
  for (int i = 0; i < n; ++i) {
    int b;
    scanf("%d", &b);
    f[i][0].adv -= b;
  }
  for (int i = 0; i < n; ++i) {
    int w;
    scanf("%d", &w);
    f[i][0].adv += w;
  }
  for (int i = 0; i < n - 1; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  traverse_tree(0);
  printf("%d\n", f[0][m - 1].inc().win);
  return 0;
}
