#include <bits/stdc++.h>
using namespace std;
const int N = 3000 + 5;
pair<int, int> dp[N][N];
pair<int, int> upd[N][N];
vector<int> graph[N];
int b[N];
int w[N];
int sz[N];
int n, m;
const int inf = 1e9 + 7;
void dfs(int v, int par = -1) {
  for (auto u : graph[v]) {
    if (u != par) {
      for (int i = 0; i <= sz[v] + sz[u]; i++) {
        upd[v][i] = {0, -inf};
      }
      dfs(u, v);
      for (int i = sz[v]; i >= 0; i--) {
        for (int j = sz[u]; j >= 0; j--) {
          upd[v][i + j] =
              max(upd[v][i + j], make_pair(dp[v][i].first + dp[u][j].first,
                                           dp[v][i].second + dp[u][j].second));
          upd[v][i + j + 1] = max(
              upd[v][i + j + 1],
              make_pair(dp[v][i].first + dp[u][j].first + (dp[u][j].second > 0),
                        dp[v][i].second));
        }
      }
      for (int i = 0; i <= sz[v] + sz[u]; i++) {
        dp[v][i] = upd[v][i];
      }
      sz[v] += sz[u];
    }
  }
  sz[v]++;
}
void solver() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      dp[i][j] = {0, 0};
    }
    graph[i].clear();
  }
  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;
    graph[u - 1].push_back(v - 1);
    graph[v - 1].push_back(u - 1);
  }
  for (int i = 0; i < n; i++) {
    dp[i][0].second = w[i] - b[i];
  }
  dfs(0);
  int ans = dp[0][m - 1].first;
  if (dp[0][m - 1].second > 0) {
    ans++;
  }
  cout << ans << '\n';
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; i++) {
    solver();
  }
}
