#include <bits/stdc++.h>
using namespace std;
void solve_case() {
  int N, M;
  cin >> N >> M;
  vector<long long> votes(N);
  for (int i = 0; i < N; ++i) {
    cin >> votes[i];
  }
  for (int i = 0; i < N; ++i) {
    long long w;
    cin >> w;
    votes[i] = w - votes[i];
  }
  vector<vector<int>> adj(N);
  for (int i = 0; i < N - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<int> sub_size(N, 1);
  pair<int, long long> null = {-N - 10, 0};
  vector<vector<pair<int, long long>>> dp(
      N, vector<pair<int, long long>>(M + 1, null));
  function<void(int, int)> dfs;
  dfs = [&](int i, int p) {
    for (int nbr : adj[i]) {
      if (nbr == p) continue;
      dfs(nbr, i);
      sub_size[i] += sub_size[nbr];
    }
    dp[i][1] = {votes[i] > 0 ? 1 : 0, votes[i]};
    for (int nbr : adj[i]) {
      if (nbr == p) continue;
      vector<pair<int, long long>> dp2(M + 1, null);
      for (int j = min(sub_size[i], M); j >= 1; --j) {
        for (int k = 1; k <= min(j, sub_size[nbr]); ++k) {
          int m = j - k + 1;
          int new_victories =
              (dp[i][m].first - (dp[i][m].second > 0 ? 1 : 0)) +
              (dp[nbr][k].first - (dp[nbr][k].second > 0 ? 1 : 0)) +
              (dp[i][m].second + dp[nbr][k].second > 0 ? 1 : 0);
          long long new_votes = dp[i][m].second + dp[nbr][k].second;
          dp2[j] = max(dp2[j], {new_victories, new_votes});
          m = j - k;
          if (m > 0) {
            new_victories = dp[i][m].first + dp[nbr][k].first;
            new_votes = dp[i][m].second;
            dp2[j] = max(dp2[j], {new_victories, new_votes});
          }
        }
      }
      dp[i] = dp2;
    }
  };
  dfs(0, -1);
  cout << dp[0][M].first << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T-- > 0) {
    solve_case();
  }
  return 0;
}
