#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<long long> a(n), b(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> b[i];
    vector<vector<int>> ad(n);
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      u--, v--;
      ad[u].push_back(v);
      ad[v].push_back(u);
    }
    for (int i = 0; i < n; i++) b[i] -= a[i];
    vector<vector<pair<int, long long>>> dp(n);
    function<void(int, int)> dfs = [&](int cur, int par) {
      vector<pair<int, long long>> cdp;
      cdp.push_back(make_pair(0, b[cur]));
      for (int ch : ad[cur]) {
        if (ch == par) continue;
        dfs(ch, cur);
        int p0 = cdp.size(), p1 = dp[ch].size();
        vector<pair<int, long long>> ndp(p0 + p1,
                                         pair<int, long long>(0, -(1LL << 50)));
        for (int i = 0; i < p0; i++) {
          for (int j = 0; j < p1; j++) {
            int bun = cdp[i].first + dp[ch][j].first;
            if (bun > ndp[i + j].first) {
              ndp[i + j] = make_pair(bun, cdp[i].second + dp[ch][j].second);
            } else if (bun == ndp[i + j].first) {
              ndp[i + j].second =
                  max(ndp[i + j].second, cdp[i].second + dp[ch][j].second);
            }
          }
        }
        cdp.swap(ndp);
      }
      for (int i = 0; i < ((int)cdp.size()) - 1; i++) {
        int ge = 0;
        if (cdp[i].second > 0) ge = 1;
        if (cdp[i + 1].first < (cdp[i].first + ge)) {
          cdp[i + 1] = make_pair(cdp[i].first + ge, 0LL);
        } else if (cdp[i + 1].first == (cdp[i].first + ge)) {
          cdp[i + 1].second = max(cdp[i + 1].second, 0LL);
        }
      }
      int sma = cdp.back().first;
      if (cdp.back().second > 0) {
        cdp.push_back(make_pair(sma + 1, 0LL));
      } else {
        cdp.push_back(make_pair(sma, 0LL));
      }
      dp[cur].swap(cdp);
    };
    dfs(0, -1);
    cout << (dp[0][m - 1].first + (dp[0][m - 1].second > 0 ? 1 : 0)) << "\n";
  }
  return 0;
}
