#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 5;
const long long INF = 1e18;
const long double EPS = 10e-9;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
long long random(long long a, long long b) {
  return uniform_int_distribution<long long>(a, b)(rng);
}
int n, m, b[N], w[N], sz[N];
vector<int> adj[N];
bool used[N];
pair<int, long long> dp[N][N], temp[N];
void init() {
  for (int i = 0; i < n; i++) {
    used[i] = false;
    adj[i].clear();
  }
}
void DFS(int u) {
  used[u] = true;
  sz[u] = 1;
  dp[u][1] = make_pair(0, w[u] - b[u]);
  for (int v : adj[u]) {
    if (not used[v]) {
      DFS(v);
      int s = sz[u] + sz[v] + 1;
      for (int i = 0; i < s; i++) temp[i] = make_pair(-1, 0LL);
      for (int x = 1; x < sz[u] + 1; x++) {
        for (int y = 1; y < sz[v] + 1; y++) {
          int z = x + y - 1;
          temp[z] = max(temp[z], {dp[u][x].first + dp[v][y].first,
                                  dp[u][x].second + dp[v][y].second});
          z = x + y;
          temp[z] = max(temp[z],
                        {dp[u][x].first +
                             (dp[v][y].first + (dp[v][y].second > 0 ? 1 : 0)),
                         dp[u][x].second});
        }
      }
      for (int i = 0; i < s; i++) dp[u][i] = temp[i];
      sz[u] += sz[v];
    }
  }
}
void solve() {
  cin >> n >> m;
  init();
  for (int i = 0; i < n; i++) cin >> b[i];
  for (int i = 0; i < n; i++) cin >> w[i];
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  DFS(0);
  int ans = dp[0][m].first + (dp[0][m].second > 0);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
