#include <bits/stdc++.h>
using namespace std;
struct State {
  long long win;
  long long delta;
  State() {
    win = -1;
    delta = 0;
  }
  State(long long win_, long long delta_) {
    win = win_;
    delta = delta_;
  }
  State solve() const { return State(win + (delta > 0), 0); }
  State operator+(const State &other) const {
    return State(win + other.win, delta + other.delta);
  }
  bool operator<(const State &other) const {
    if (win != other.win) {
      return win < other.win;
    } else {
      return delta < other.delta;
    }
  }
};
vector<State> mrg(const vector<State> &a, const vector<State> &b) {
  vector<State> res(a.size() + b.size());
  for (long long i = 0; i < (long long)a.size(); i++) {
    for (long long j = 0; j < (long long)b.size(); j++) {
      res[i + j] = max(res[i + j], a[i] + b[j]);
      res[i + j + 1] = max(res[i + j + 1], a[i] + b[j].solve());
    }
  }
  return res;
}
long long n;
vector<vector<long long>> g;
vector<vector<State>> dp;
void dfs(long long cur, long long p) {
  for (auto t : g[cur]) {
    if (t == p) {
      continue;
    }
    dfs(t, cur);
    dp[cur] = mrg(dp[cur], dp[t]);
  }
}
void solve() {
  g.clear();
  dp.clear();
  long long m;
  cin >> n >> m;
  g.resize(n);
  dp.resize(n, vector<State>(1));
  vector<long long> cost(n);
  for (long long i = 0; i < n; i++) {
    long long b;
    cin >> b;
    cost[i] -= b;
  }
  for (long long i = 0; i < n; i++) {
    long long w;
    cin >> w;
    cost[i] += w;
  }
  for (long long i = 0; i < n; i++) {
    dp[i][0] = State(0, cost[i]);
  }
  for (long long i = 0; i + 1 < n; i++) {
    long long u, v;
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  cout << dp[0][m - 1].solve().win << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) {
    solve();
  }
}
