#include <bits/stdc++.h>
using namespace std;
long long n, m, val[3003], s[3003];
pair<long long, long long> dp[3003][3003];
pair<long long, long long> temp[3003][3003];
vector<long long> a[3003];
void pre(long long node, long long par) {
  s[node] = 1;
  for (auto i : a[node]) {
    if (i != par) {
      pre(i, node);
      s[node] += s[i];
    }
  }
}
void dfs(long long node, long long par) {
  dp[node][0] = {0, 0};
  long long cur = 1;
  for (auto i : a[node]) {
    if (i != par) {
      dfs(i, node);
      for (long long k = 0; k < s[node] + 1; k++)
        temp[node][k] = {-1, 1000000007};
      for (long long k = 0; k < cur + 1; k++) {
        for (long long j = 0; j < s[i] + 1; j++) {
          pair<long long, long long> w = {dp[node][k].first + dp[i][j].first,
                                          dp[node][k].second + dp[i][j].second};
          temp[node][k + j] = max(temp[node][k + j], w);
        }
      }
      for (long long k = 0; k < s[node] + 1; k++) dp[node][k] = temp[node][k];
      cur += s[i];
    }
  }
  for (long long k = 0; k < s[node]; k++) dp[node][k].second += val[node];
  for (long long k = 0; k < s[node]; k++)
    dp[node][k + 1] =
        max(dp[node][k + 1],
            make_pair(dp[node][k].first + (dp[node][k].second > 0), 0LL));
}
void solve() {
  cin >> n >> m;
  for (long long i = 1; i < n + 1; i++) {
    val[i] = 0;
    a[i].clear();
    s[i] = 0;
  }
  for (long long i = 1; i < n + 1; i++) {
    long long first;
    cin >> first;
    val[i] -= first;
  }
  for (long long i = 1; i < n + 1; i++) {
    long long first;
    cin >> first;
    val[i] += first;
  }
  for (long long i = 0; i < n - 1; i++) {
    long long first, second;
    cin >> first >> second;
    a[first].push_back(second);
    a[second].push_back(first);
  }
  for (long long i = 1; i < n + 1; i++) {
    for (long long j = 0; j < m + 1; j++) {
      dp[i][j] = {-1, -1000000007};
    }
  }
  pre(1, -1);
  dfs(1, -1);
  cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << '\n';
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
