#include <bits/stdc++.h>
using namespace std;
vector<int> adj[1000000];
long long a[1000000];
pair<int, long long> dp[3001][3001];
pair<int, long long> tmp[3001][3001];
long long sub[1000000];
int num[1000000];
void pre(int v = 1, int p = 0) {
  sub[v] = a[v];
  num[v] = 1;
  for (auto u : adj[v]) {
    if (u == p) continue;
    pre(u, v);
    sub[v] += sub[u];
    num[v] += num[u];
  }
}
pair<int, long long> operator+(pair<int, long long> A, pair<int, long long> B) {
  return {A.first + B.first, A.second + B.second};
}
void dfs(int v = 1, int p = 0) {
  dp[v][0] = {0, sub[v]};
  if (sub[v] > 0)
    dp[v][1] = {1, 0};
  else
    dp[v][1] = {0, sub[v]};
  int sz = 1;
  for (auto u : adj[v]) {
    if (p == u) continue;
    dfs(u, v);
    for (int i = 0; i <= sz + num[u]; i++) tmp[v][i] = dp[v][i];
    for (int i = 1; i <= sz; i++) {
      for (int j = 0; j <= num[u]; j++) {
        dp[v][j + i] =
            max(dp[v][j + i], tmp[v][i] + dp[u][j] + make_pair(0, a[v]));
      }
    }
    sz += num[u];
  }
  for (int i = 0; i <= num[v]; i++) {
    if (dp[v][i].second > 0) {
      dp[v][i + 1] = max(dp[v][i + 1], {dp[v][i].first + 1, 0});
    } else {
      dp[v][i + 1] = max(dp[v][i + 1], dp[v][i]);
    }
  }
}
int b[1000000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; i++)
      for (int j = 0; j <= n; j++) dp[i][j] = {0, -1e16};
    for (int i = 1; i <= n; i++) {
      cin >> b[i];
      a[i] = b[i] - a[i];
    }
    for (int i = 1; i <= n; i++) adj[i].clear();
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    pre();
    dfs();
    int ret = 0;
    if (dp[1][m].second >= 0)
      ret = dp[1][m].first;
    else
      ret = dp[1][m].first - 1;
    ret = max(ret, 0);
    cout << ret << endl;
  }
}
