#include <bits/stdc++.h>
using namespace std;
const long long N = 3005;
const long long INF = 1ll << 60;
long long n, m, t, vot[N], sub[N];
pair<int, long long> dp[N][N], dp2[N];
vector<int> adj[N];
void dfs(int v, int p = -1) {
  dp[v][1] = {0, vot[v]};
  sub[v] = 1;
  for (auto u : adj[v]) {
    if (p != u) {
      dfs(u, v);
      for (int i = 1; i <= sub[v] + sub[u]; i++) dp2[i] = {0, -INF};
      for (int i = 1; i <= sub[v]; i++)
        for (int j = 1; j <= sub[u]; j++) {
          dp2[i + j] = max(dp2[i + j], {dp[v][i].first + dp[u][j].first +
                                            (dp[u][j].second > 0 ? 1 : 0),
                                        dp[v][i].second});
          dp2[i + j - 1] =
              max(dp2[i + j - 1], {dp[v][i].first + dp[u][j].first,
                                   dp[v][i].second + dp[u][j].second});
        }
      for (int i = 1; i <= sub[v] + sub[u]; i++) dp[v][i] = dp2[i];
      sub[v] += sub[u];
    }
  }
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1, x; i <= n; i++) {
      cin >> x;
      vot[i] -= x;
    }
    for (int i = 1, x; i <= n; i++) {
      cin >> x;
      vot[i] += x;
    }
    for (int i = 1, v, u; i < n; i++) {
      cin >> v >> u;
      adj[v].push_back(u);
      adj[u].push_back(v);
    }
    dfs(1);
    cout << dp[1][m].first + (dp[1][m].second > 0 ? 1 : 0) << '\n';
    memset(vot, 0, sizeof vot);
    for (int i = 0; i <= n; i++) adj[i].clear();
  }
}
