#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int N, M;
vector<long long> B, W;
vector<int> g[3003];
pair<int, long long> dp[3003][3003][2];
int num[3003];
const long long INF = 1e15;
void chmax(pair<int, long long> &a, pair<int, long long> b) {
  if (a.first < b.first)
    a = b;
  else if (a.first == b.first && a.second < b.second)
    a = b;
  return;
}
void dfs(int now, int par) {
  for (auto nx : g[now]) {
    if (nx != par) dfs(nx, now);
  }
  int sum = 0;
  int t = 0;
  dp[now][0][t] = make_pair(0, W[now] - B[now]);
  for (int i = 0; i < g[now].size(); i++) {
    int nx = g[now][i];
    if (nx == par) continue;
    for (int j = sum; j >= 0; j--) {
      for (int k = 0; k <= num[nx]; k++) {
        {
          chmax(dp[now][j + k][1 - t],
                make_pair(dp[now][j][t].first + dp[nx][k][0].first,
                          dp[now][j][t].second + dp[nx][k][0].second));
        }
        {
          int win = 0;
          if (dp[nx][k][0].second > 0) win = 1;
          chmax(dp[now][j + k + 1][1 - t],
                make_pair(dp[now][j][t].first + dp[nx][k][0].first + win,
                          dp[now][j][t].second));
        }
      }
    }
    for (int j = 0; j <= sum; j++) dp[now][j][t] = make_pair(-N * 100, -INF);
    sum += num[nx] + 1;
    t = 1 - t;
  }
  for (int j = 0; j <= sum; j++) dp[now][j][1 - t] = dp[now][j][t];
  num[now] = sum;
}
void solve() {
  cin >> N >> M;
  B.clear();
  W.clear();
  B.resize(N);
  W.resize(N);
  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; i++) g[i].clear();
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 0; i <= N; i++)
    for (int j = 0; j <= N; j++) {
      dp[i][j][0] = make_pair(-N * 100, -INF);
      dp[i][j][1] = make_pair(-N * 100, -INF);
    }
  dfs(0, -1);
  long long ans = dp[0][M - 1][0].first;
  if (dp[0][M - 1][0].second > 0) ans++;
  cout << ans << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int T;
  cin >> T;
  for (int i = 0; i < (T); ++i) solve();
  return 0;
}
