#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using dd = double;
using ldd = long double;
template <typename T1, typename T2>
inline void checkMin(T1& a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void checkMax(T1& a, T2 b) {
  if (a < b) a = b;
}
vector<vector<int>> gr;
vector<vector<pair<int, ll>>> dp;
vector<int> cnt;
vector<int> w;
void dfs(int v, int p = -1) {
  cnt[v] = 1;
  for (int to : gr[v]) {
    if (to == p) continue;
    dfs(to, v);
    cnt[v] += cnt[to];
  }
  for (int i = 0; i < dp[v].size(); ++i) {
    dp[v][i] = {0, -1e18};
  }
  dp[v][1] = {0, w[v]};
  int mec = 1;
  for (int to : gr[v]) {
    if (to == p) continue;
    vector<pair<int, ll>> dpp(mec + cnt[to] + 1, {0, -1e18});
    for (int toV = 1; toV <= cnt[to]; ++toV) {
      for (int me = 1; me <= mec; ++me) {
        dpp[toV + me - 1] =
            max(dpp[toV + me - 1], {dp[v][me].first + dp[to][toV].first,
                                    dp[v][me].second + dp[to][toV].second});
        if (dp[v][me].second > 0 && dp[to][toV].second > 0) {
          dpp[toV + me] =
              max(dpp[toV + me],
                  {dp[v][toV].first + dp[to][toV].first + 1,
                   max(dp[v][me].second, dp[to][toV].second + w[v])});
        } else if (dp[v][me].second <= 0 && dp[to][toV].second <= 0) {
          dpp[toV + me] =
              max(dpp[toV + me],
                  {dp[v][toV].first + dp[to][toV].first,
                   max(dp[to][toV].second, dp[v][me].second + w[v])});
        } else {
          dpp[toV + me] =
              max(dpp[toV + me], {dp[v][toV].first + dp[to][toV].first +
                                      (dp[to][toV].second > 0 ? 1 : 0),
                                  dp[v][me].second});
          dpp[toV + me] =
              max(dpp[toV + me], {dp[v][toV].first + dp[to][toV].first +
                                      (dp[v][me].second - w[v] > 0 ? 1 : 0),
                                  dp[to][toV].second + w[v]});
        }
      }
    }
    dp[v] = dpp;
    mec += cnt[to];
  }
  0;
  ;
  0;
  ;
}
void solve() {
  int n, m;
  cin >> n >> m;
  gr.clear();
  gr.resize(n);
  w.resize(n);
  cnt.clear();
  cnt.resize(n);
  dp.clear();
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    w[i] -= x;
  }
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  dp.resize(n, vector<pair<int, ll>>(n + 1));
  0;
  ;
  dfs(0);
  0;
  ;
  cout << (dp[0][m].first + (dp[0][m].second > 0 ? 1 : 0));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  t = 1;
  cin >> t;
  for (int i = 0; i < t; ++i) {
    solve();
    cout << '\n';
  }
  return 0;
}
