#include <bits/stdc++.h>
using namespace std;
vector<int> G[3009];
int C[3009], deg[3009], sub[3009];
long long sum[3009];
void dfs(int x, int p) {
  if (C[x] > 0)
    sub[x] = 1;
  else
    sub[x] = 0;
  sum[x] = C[x];
  deg[x] = G[x].size();
  for (auto& it : G[x])
    if (it != p) {
      dfs(it, x);
      sum[x] += sum[it];
      sub[x] += sub[it];
    }
  vector<long long> S;
  for (auto& it : G[x])
    if (it != p) {
      if (sub[it] == 0) S.push_back(-sum[it]);
    }
  sort(S.begin(), S.end());
  long long t = C[x];
  for (auto& it : S) {
    if (t - it <= 0) break;
    t -= it;
    --deg[x];
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int N, M;
    scanf("%d%d", &N, &M);
    for (int i = 1; i <= N; i++) {
      G[i].clear();
      C[i] = deg[i] = sub[i] = sum[i] = 0;
    }
    for (int i = 1; i <= N; i++) {
      int foo;
      scanf("%d", &foo);
      C[i] -= foo;
    }
    for (int i = 1; i <= N; i++) {
      int foo;
      scanf("%d", &foo);
      C[i] += foo;
    }
    int rt = -1;
    for (int i = 1; i <= N; i++)
      if (C[i] > 0) rt = i;
    if (rt == -1) {
      puts("0");
      continue;
    }
    for (int i = 0; i < N - 1; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    dfs(rt, rt);
    vector<int> S;
    for (int i = 1; i <= N; i++)
      if (C[i] > 0) S.push_back(i);
    sort(S.begin(), S.end(), [&](int P, int Q) { return deg[P] < deg[Q]; });
    int c = 1, ans = 0;
    for (auto& it : S) {
      if (c + deg[it] > M)
        break;
      else
        ++ans;
    }
    printf("%d\n", ans);
  }
  return 0;
}
