#include <bits/stdc++.h>
using namespace std;
const int MAX = (2e5) + 5;
int B[MAX], W[MAX];
vector<int> mat[MAX];
int chi[MAX], sib[MAX], sz[MAX];
void dfs(int p, int pa) {
  int lc = -1;
  for (int x : mat[p]) {
    if (x == pa) {
      continue;
    }
    dfs(x, p);
    (lc == -1) ? (chi[p] = x) : (sib[lc] = x);
    lc = x;
  }
}
void dudu(int p) {
  if (p == -1) {
    return;
  }
  sz[p] = 1;
  dudu(sib[p]);
  dudu(chi[p]);
  if (sib[p] != -1) {
    sz[p] += sz[sib[p]];
  }
  if (chi[p] != -1) {
    sz[p] += sz[chi[p]];
  }
}
const int dpMAX = (3e3) + 5;
pair<int, long long> dp[dpMAX][dpMAX];
bool vis[dpMAX][dpMAX];
pair<int, long long> rec(int p, int r) {
  if ((p == -1) || (sz[p] > r)) {
    if (r)
      return {-3000, 0};
    else
      return {0, 0};
  }
  if (vis[p][r]) {
    return dp[p][r];
  }
  vis[p][r] = 1;
  pair<int, long long> temp = {-3000, -(1e14)};
  for (int i = 0; i <= r - 1; i++) {
    pair<int, long long> c = rec(chi[p], i);
    pair<int, long long> s = rec(sib[p], (r - 1) - i);
    c.second += (W[p] - B[p]);
    (c.second > 0) ? c.first++ : c.first;
    c.second = 0;
    c.first += s.first;
    c.second += s.second;
    temp = max(temp, c);
  }
  if (p != 1) {
    for (int i = 0; i <= r; i++) {
      pair<int, long long> c = rec(chi[p], i);
      pair<int, long long> s = rec(sib[p], r - i);
      c.second += (W[p] - B[p]);
      c.first += s.first;
      c.second += s.second;
      temp = max(temp, c);
    }
  }
  return dp[p][r] = temp;
}
void solve() {
  int n, m, u, v;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> B[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> W[i];
  }
  for (int i = 1; i <= n - 1; i++) {
    cin >> u >> v;
    mat[u].push_back(v);
    mat[v].push_back(u);
  }
  memset(chi, -1, sizeof(chi));
  memset(sib, -1, sizeof(sib));
  memset(vis, 0, sizeof(vis));
  dfs(1, 1);
  dudu(1);
  cout << rec(1, m).first << endl;
  for (int i = 1; i <= n; i++) {
    mat[i].clear();
  }
}
int main() {
  ios::sync_with_stdio(false);
  int tc;
  cin >> tc;
  for (int tt = 1; tt <= tc; tt++) {
    solve();
  }
  return 0;
}
