#include <bits/stdc++.h>
using namespace std;
const int N = 3000 + 10;
const int inf = 1e9;
vector<int> c[N];
pair<int, long long> dp[N][N], tmp[N];
int a[N], b[N];
int sz[N];
int n, m;
void dfs(int s, int p) {
  sz[s] = 1;
  dp[s][1] = {0, a[s] - b[s]};
  for (auto x : c[s])
    if (x != p) {
      dfs(x, s);
      fill(tmp, tmp + sz[s] + sz[x] + 1, pair<int, long long>(-inf, -inf));
      for (int k = 1; k <= sz[s]; k++)
        for (int p = 1; p <= sz[x]; p++) {
          tmp[k + p - 1] =
              max(tmp[k + p - 1], {dp[s][k].first + dp[x][p].first,
                                   dp[s][k].second + dp[x][p].second});
          tmp[k + p] = max(tmp[k + p], {dp[s][k].first + (dp[x][p].second > 0),
                                        dp[s][k].second});
        }
      copy(tmp, tmp + sz[s] + sz[x] + 1, dp[s]);
      sz[s] += sz[x];
    }
}
void solve() {
  memset(dp, -63, sizeof dp);
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> a[i];
  fill(c, c + n, vector<int>());
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    c[u].push_back(v);
    c[v].push_back(u);
  }
  dfs(0, 0);
  cout << dp[0][m].first + (dp[0][m].second > 0) << '\n';
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
