#include <bits/stdc++.h>
using namespace std;
int T;
int N, M;
int B[3030], W[3030];
vector<int> E[3030];
vector<pair<int, signed long long>> conv(
    vector<pair<int, signed long long>> A,
    vector<pair<int, signed long long>> B) {
  int a = A.size(), b = B.size();
  vector<pair<int, signed long long>> C(a + b, {-10000, 0});
  int x, y;
  for (x = 0; x < (a); x++)
    for (y = 0; y < (b); y++) {
      C[x + y + 1] =
          max(C[x + y + 1],
              {A[x].first + B[y].first + (B[y].second > 0), A[x].second});
      C[x + y] =
          max(C[x + y], {A[x].first + B[y].first, A[x].second + B[y].second});
    }
  return C;
}
vector<pair<int, signed long long>> dfs(int cur, int pre) {
  vector<pair<int, signed long long>> V;
  V.push_back({0, W[cur] - B[cur]});
  for (auto& e : E[cur])
    if (e != pre) V = conv(V, dfs(e, cur));
  return V;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> T;
  while (T--) {
    cin >> N >> M;
    for (i = 0; i < (N); i++) cin >> B[i];
    for (i = 0; i < (N); i++) cin >> W[i];
    for (i = 0; i < (N); i++) E[i].clear();
    for (i = 0; i < (N - 1); i++) {
      cin >> x >> y;
      E[x - 1].push_back(y - 1);
      E[y - 1].push_back(x - 1);
    }
    auto v = dfs(0, 0);
    cout << v[M - 1].first + (v[M - 1].second > 0) << endl;
  }
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
