#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int A[3005], B[3005], sz[3005];
pair<ll, ll> dp[3005][3005], t[3005];
vector<int> edge[3005];
void dfs(int x, int p) {
  sz[x] = 1;
  dp[x][1] = {0, A[x] - B[x]};
  for (auto i : edge[x]) {
    if (i == p) continue;
    dfs(i, x);
    for (int j = 1; j <= sz[x] + sz[i]; ++j) t[j] = {-1e18, 0};
    for (int j = sz[x]; j; --j) {
      for (int k = sz[i]; k; --k) {
        t[j + k] = max(t[j + k], make_pair(dp[x][j].first + dp[i][k].first +
                                               (dp[i][k].second > 0),
                                           dp[x][j].second));
        t[j + k - 1] =
            max(t[j + k - 1], make_pair(dp[x][j].first + dp[i][k].first,
                                        dp[x][j].second + dp[i][k].second));
      }
    }
    sz[x] += sz[i];
    for (int j = 1; j <= sz[x]; ++j) dp[x][j] = t[j];
  }
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) edge[i].clear();
    for (int i = 1; i <= N; ++i)
      for (int j = 1; j <= N; ++j) dp[i][j] = {-1e18, 0};
    for (int i = 1; i <= N; ++i) cin >> B[i];
    for (int i = 1; i <= N; ++i) cin >> A[i];
    for (int i = 1; i < N; ++i) {
      int x, y;
      cin >> x >> y;
      edge[x].push_back(y);
      edge[y].push_back(x);
    }
    dfs(1, 1);
    printf("%lld\n", dp[1][M].first + (dp[1][M].second > 0));
  }
  return 0;
}
