#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > edges;
vector<int> dp;
void functor(pair<int, long long>& a, pair<int, long long> b) {
  if (b > a) a = b;
}
vector<pair<int, long long> > dfs(int v, int p) {
  vector<pair<int, long long> > f = {{0, dp[v]}};
  for (int w : edges[v]) {
    if (w == p) continue;
    vector<pair<int, long long> > x = dfs(w, v);
    vector<pair<int, long long> > nuevo_dfs(f.size() + x.size(), {0, -1e16});
    for (int i = 0; i < (int)f.size(); i++) {
      for (int j = 0; j < (int)x.size(); j++) {
        pair<int, long long> r = f[i], s = x[j];
        { functor(nuevo_dfs[i + j], {r.first + s.first, r.second + s.second}); }
        {
          functor(nuevo_dfs[i + j + 1],
                  {r.first + s.first + (s.second > 0), r.second});
        }
      }
    }
    f = nuevo_dfs;
  }
  return f;
}
void resolver() {
  int n, m;
  cin >> n >> m;
  dp.assign(n, 0);
  edges.assign(n, {});
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dp[i] -= x;
  }
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    dp[i] += x;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  vector<pair<int, long long> > res = dfs(0, -1);
  int ans = res[m - 1].first;
  if (res[m - 1].second > 0) ans++;
  cout << ans << '\n';
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    resolver();
  }
}
