#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const int maxn = 1e6 + 5;
struct dat {
  ll win, bal;
  dat(ll w = -1, ll b = 0) {
    win = w;
    bal = b;
  }
  dat operator+(const dat& o) const { return dat{win + o.win, bal + o.bal}; }
  dat operator+() const { return dat(win + (bal > 0)); }
  bool operator<(const dat& o) const {
    if (win < o.win) return true;
    if (win > o.win) return false;
    assert(win == o.win);
    return bal < o.bal;
  }
};
int n, m;
vector<vector<int>> g;
vector<vector<dat>> dp;
vector<dat> merge(vector<dat> v, vector<dat> w) {
  int n = v.size();
  int m = w.size();
  vector<dat> res(n + m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      res[i + j] = max(res[i + j], v[i] + w[j]);
      res[i + j + 1] = max(res[i + j + 1], v[i] + +w[j]);
    }
  }
  return res;
}
void dfs(int at, int p) {
  for (int to : g[at]) {
    if (to == p) continue;
    dfs(to, at);
    dp[at] = merge(dp[at], dp[to]);
  }
}
int solve() {
  cin >> n >> m;
  dp = vector<vector<dat>>(n, vector<dat>(1, dat{0, 0}));
  for (int i = 0; i < n; i++) {
    ll b;
    cin >> b;
    dp[i][0].bal -= b;
  }
  for (int i = 0; i < n; i++) {
    ll w;
    cin >> w;
    dp[i][0].bal += w;
  }
  g = vector<vector<int>>(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  dat res = +dp[0][m - 1];
  return res.win;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << "\n";
  }
  return 0;
}
