#include <bits/stdc++.h>
using namespace std;
const int nax = 3005;
int n, m;
vector<int> v[nax];
int a, b;
int B[nax], W[nax];
pair<int, long long> dp[nax][nax][2];
pair<int, long long> dp2[nax][2];
int siz[nax];
pair<int, long long> merge1(pair<int, long long> A, pair<int, long long> B) {
  pair<int, int> C;
  C.first = A.first + B.first;
  C.second = A.second;
  return C;
}
pair<int, long long> merge2(pair<int, long long> A, pair<int, long long> B) {
  pair<int, int> C;
  C.first = A.first + B.first;
  C.second = A.second + B.second;
  return C;
}
void napraw(pair<int, long long> &A) {
  if (A.second > 0) A.first++;
  A.second = 0;
}
void dfs(int u, int p) {
  siz[u] = 1;
  dp[u][1][1] = make_pair(0, W[u] - B[u]);
  dp[u][1][0] = make_pair(0, W[u] - B[u]);
  for (auto it : v[u]) {
    if (it == p) continue;
    dfs(it, u);
    for (int i = 1; i <= min(m, siz[it] + siz[u]); ++i) {
      dp2[i][0] = make_pair(-1, 0);
      dp2[i][1] = make_pair(-1, 0);
    }
    for (int i = 1; i <= siz[u]; ++i)
      for (int j = 1; j <= siz[it] && i + j <= m + 1; ++j) {
        dp2[i + j][1] = max(dp2[i + j][1], merge1(dp[u][i][1], dp[it][j][1]));
        dp2[i + j - 1][1] =
            max(dp2[i + j - 1][1], merge2(dp[u][i][1], dp[it][j][0]));
        dp2[i + j][0] = max(dp2[i + j][0], merge1(dp[u][i][0], dp[it][j][1]));
        dp2[i + j - 1][0] =
            max(dp2[i + j - 1][0], merge2(dp[u][i][0], dp[it][j][0]));
      }
    for (int i = 1; i <= min(m, siz[it] + siz[u]); ++i) {
      dp[u][i][0] = dp2[i][0];
      dp[u][i][1] = dp2[i][1];
    }
    siz[u] += siz[it];
  }
  for (int i = 1; i <= min(m, siz[u]); ++i) napraw(dp[u][i][1]);
}
void go() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) v[i].clear();
  for (int i = 1; i <= n; ++i) scanf("%d", B + i);
  for (int i = 1; i <= n; ++i) scanf("%d", W + i);
  for (int i = 1; i < n; ++i) {
    scanf("%d %d", &a, &b);
    v[a].push_back(b);
    v[b].push_back(a);
  }
  for (int i = 1; i <= n; ++i)
    for (int j = 0; j <= m; ++j) {
      dp[i][j][0] = make_pair(-1, 0);
      dp[i][j][1] = make_pair(-1, 0);
    }
  dfs(1, 0);
  printf("%d\n", dp[1][m][1].first);
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) go();
  return 0;
}
