#include <bits/stdc++.h>
using namespace std;
struct __timestamper {};
const long long INF = 1e18;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    vector<int> b(n), w(n);
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    for (int i = 0; i < n; i++) scanf("%d", &w[i]);
    vector<vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      u--;
      v--;
      e[u].push_back(v);
      e[v].push_back(u);
    }
    vector<vector<pair<int, long long>>> dp(n);
    vector<int> sz(n);
    function<void(int, int)> dfs = [&](int v, int pr) {
      sz[v] = 1;
      vector<pair<int, long long>> cdp(sz[v] + 1, make_pair(0, -INF));
      cdp[0] = make_pair(0, w[v] - b[v]);
      for (int to : e[v]) {
        if (to == pr) continue;
        dfs(to, v);
        vector<pair<int, long long>> ndp(sz[v] + sz[to] + 1,
                                         make_pair(0, -INF));
        for (int sz1 = 0; sz1 <= sz[v]; sz1++) {
          for (int sz2 = 0; sz2 <= sz[to]; sz2++) {
            ndp[sz1 + sz2] =
                max(ndp[sz1 + sz2],
                    make_pair(cdp[sz1].first + dp[to][sz2].first,
                              cdp[sz1].second + dp[to][sz2].second));
          }
        }
        sz[v] += sz[to];
        cdp.swap(ndp);
      }
      for (int i = sz[v] - 1; i >= 0; i--) {
        cdp[i + 1] =
            max(cdp[i + 1], make_pair(cdp[i].first + (cdp[i].second > 0), 0LL));
      }
      dp[v].swap(cdp);
    };
    dfs(0, -1);
    int res = dp[0][m - 1].first + (dp[0][m - 1].second > 0);
    cout << res << endl;
  }
  return 0;
}
