#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 10, mod = 1e9 + 7;
const long long inf = 1ll * mod * mod;
int a[N], sz[N];
pair<int, long long> dp[N][N], hlp[N];
vector<int> g[N];
void dfs(int v, int p) {
  sz[v] = 1;
  dp[v][1] = {0, a[v]};
  for (int u : g[v])
    if (u != p) {
      dfs(u, v);
      for (int i = 1; i <= sz[v]; i++) hlp[i] = {-mod, -inf};
      for (int i = 1; i <= sz[v]; i++) {
        for (int j = 1; j <= sz[u]; j++) {
          hlp[i + j - 1] =
              max(hlp[i + j - 1], {dp[v][i].first + dp[u][j].first,
                                   dp[v][i].second + dp[u][j].second});
          hlp[i + j] = max(hlp[i + j], {dp[v][i].first + dp[u][j].first +
                                            (dp[u][j].second > 0),
                                        dp[v][i].second});
        }
      }
      for (int i = 1; i <= sz[v] + sz[u]; i++) dp[v][i] = hlp[i];
      sz[v] += sz[u];
    }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      a[i] = x - a[i];
    }
    for (int i = 0; i < n; i++) {
      g[i].clear();
      for (int j = 0; j <= n; j++) dp[i][j] = {-mod, -inf};
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(0, 0);
    cout << dp[0][m].first + (dp[0][m].second > 0) << "\n";
  }
  return 0;
}
