#include <bits/stdc++.h>
using namespace std;
vector<int> adj[3000];
int N, Mx[3000];
bool chk[3000];
pair<int, long long> D[3000][3001], temp[3001];
void dfs(int c) {
  chk[c] = true;
  for (auto n : adj[c])
    if (!chk[n]) {
      dfs(n);
      for (int i = Mx[c] + Mx[n]; i > 0; i--)
        temp[i] = {0, -0x7fffffffffffffffLL};
      for (int i = Mx[c]; i > 0; i--)
        for (int j = Mx[n]; j > 0; j--) {
          pair<int, long long> T(
              D[c][i].first + D[n][j].first + (D[n][j].second > 0),
              D[c][i].second);
          if (temp[i + j] < T) temp[i + j] = T;
          T = {D[c][i].first + D[n][j].first, D[c][i].second + D[n][j].second};
          if (temp[i + j - 1] < T) temp[i + j - 1] = T;
        }
      for (int i = Mx[c] += Mx[n]; i > 0; i--) D[c][i] = temp[i];
    }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ((void)0);
  ((void)0);
  ((void)0);
  int T, N, M;
  for (cin >> T; T--;) {
    cin >> N >> M;
    memset(D, 0, sizeof(D));
    memset(chk, 0, sizeof(chk));
    for (int i = 0; i < N; i++) {
      cin >> D[i][1].second;
      D[i][1].second *= -1;
      Mx[i] = 1;
      for (int j = 2; j <= N; j++) D[i][j] = {0, 0};
      adj[i].clear();
    }
    for (int i = 0; i < N; i++) {
      int v;
      cin >> v;
      D[i][1].second += v;
    }
    for (int i = 1; i < N; i++) {
      int a, b;
      cin >> a >> b;
      adj[--a].push_back(--b);
      adj[b].push_back(a);
    }
    dfs(0);
    cout << D[0][M].first + (D[0][M].second > 0) << '\n';
  }
  return 0;
}
