#include <bits/stdc++.h>
using namespace std;
vector<int> edge[3001];
int n, m, bee[3001], sz[3001], wasp[3001], w[3001];
pair<int, int> result[3001][3001], f[3001][3001];
void dfs(int u, int pre) {
  cout << u << " " << pre << '\n';
  sz[u] = 1;
  int a[3001], cnt = 0, cur = 0;
  for (auto v : edge[u]) {
    if (v == pre) {
      continue;
    }
    dfs(v, u);
    sz[u] += sz[v];
    a[++cnt] = v;
  }
  for (int e = 1; e <= 3000; e++) {
    f[0][e] = pair<int, int>(-1e9, -1e9);
    result[u][e] = result[u][0] = pair<int, int>(-1e9, -1e9);
  }
  for (int i = 1; i <= cnt; i++) {
    for (int e = 0; e <= 3000; e++) {
      f[i][e] = pair<int, int>(-1e9, -1e9);
    }
    cur += sz[a[i]];
    for (int e = cur; e >= 0; e--) {
      for (int g = 0; g <= min(e, sz[a[i]]); g++) {
        pair<int, int> ide =
            pair<int, int>(result[a[i]][g].first + f[i - 1][e - g].first,
                           result[a[i]][g].second + f[i - 1][e - g].second);
        f[i][e] = max(f[i][e], ide);
      }
    }
  }
  for (int i = 0; i <= cur + 1; i++) {
    if (i > 0) {
      if (f[cnt][i - 1].second + w[u] > 0) {
        result[u][i] = f[cnt][i - 1];
        result[u][i].first++;
        result[u][i].second = 0;
      } else {
        result[u][i] = f[cnt][i - 1];
        result[u][i].second = 0;
      }
    }
    result[u][i] = max(
        result[u][i], pair<int, int>(f[cnt][i].first, f[cnt][i].second + w[u]));
  }
  if (cnt == 0) {
    result[u][0] = pair<int, int>(0, w[u]);
    result[u][1] = pair<int, int>(0, 0);
    if (w[u] > 0) {
      result[u][1].first++;
    }
  }
}
int main() {
  int test;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> test;
  while (test--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      edge[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      cin >> bee[i];
    }
    for (int i = 1; i <= n; i++) {
      cin >> wasp[i];
    }
    for (int i = 1; i <= n; i++) {
      w[i] = wasp[i] - bee[i];
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      edge[u].push_back(v);
      edge[v].push_back(u);
    }
    dfs(1, 0);
    if (result[1][m - 1].second <= 0) {
      cout << result[1][m - 1].first << '\n';
    } else {
      cout << result[1][m - 1].first + 1 << '\n';
    }
  }
}
