#include <bits/stdc++.h>
using namespace std;
int tt;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> tt;
  for (int tc = 1; tc <= tt; tc++) {
    int n, m;
    cin >> n >> m;
    vector<int> b(n), w(n);
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) cin >> w[i];
    vector<vector<int>> g(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);
    }
    auto merge = [&](vector<pair<int, long long>> &a,
                     vector<pair<int, long long>> b) {
      vector<pair<int, long long>> res(a.size() + b.size(),
                                       make_pair(INT_MIN, LLONG_MIN));
      for (int i = 0; i < (int)a.size(); i++) {
        for (int j = 0; j < (int)b.size(); j++) {
          pair<int, long long> c;
          c.first = a[i].first + b[j].first;
          c.second = a[i].second + b[j].second;
          if (c.second > 0) c.first++;
          res[i + j] = max(res[i + j], c);
          c.first = a[i].first + b[j].first + (b[j].second > 0);
          c.second = a[i].second;
          res[i + j + 1] = max(res[i + j + 1], c);
        }
      }
      a = res;
    };
    function<vector<pair<int, long long>>(int, int)> dfs = [&](int v, int par) {
      vector<pair<int, long long>> res = {{w[v] > b[v], 0}};
      for (int i : g[v]) {
        if (i == par) continue;
        merge(res, dfs(i, v));
      }
      return res;
    };
    vector<pair<int, long long>> res = dfs(0, -1);
    cout << res[m - 1].first + (res[m - 1].second > 0) << endl;
  }
  return 0;
}
