#include <bits/stdc++.h>
using namespace std;
template <class T1, class T2>
istream &operator>>(istream &in, pair<T1, T2> &P) {
  in >> P.first >> P.second;
  return in;
}
template <class T1, class T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &P) {
  out << "(" << P.first << ", " << P.second << ")";
  return out;
}
template <class T>
istream &operator>>(istream &in, vector<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const vector<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
template <class T>
istream &operator>>(istream &in, deque<T> &arr) {
  for (auto &x : arr) in >> x;
  return in;
}
template <class T>
ostream &operator<<(ostream &out, const deque<T> &arr) {
  for (auto &x : arr) out << x << ' ';
  cout << "\n";
  return out;
}
vector<int> adj[3030];
long long pp[2][3030];
pair<long long, long long> dp[3030][3030];
pair<long long, long long> g[3030];
int sz[3030];
int n, m;
void solve(int x, int y = -1) {
  sz[x] = 1;
  dp[x][0] = pair<long long, long long>(0, pp[1][x] - pp[0][x]);
  for (auto w : adj[x]) {
    if (w == y) continue;
    solve(w, x);
    dp[w][sz[w]] = pair<long long, long long>(-(long long)1e10, 0);
    for (int j = min(sz[w], m) - 1; j >= 0; j--) {
      dp[w][j + 1] = max(dp[w][j + 1],
                         {dp[w][j].first + (dp[w][j].second > 0 ? 1 : 0), 0});
    }
    for (int j = 0; j < (min(m, sz[x] + sz[w])); ++j) {
      g[j] = pair<long long, long long>(-1, -1);
    }
    for (int k = min(m - 1, sz[x]); k >= 0; k--) {
      for (int j = 0; j <= min(sz[w], m - 1); j++) {
        if (j + k >= m) break;
        g[j + k] = max(g[j + k], pair<long long, long long>(
                                     dp[x][k].first + dp[w][j].first,
                                     dp[x][k].second + dp[w][j].second));
      }
    }
    sz[x] += sz[w];
    for (int j = 0; j < (min(sz[x], m)); ++j) {
      dp[x][j] = g[j];
    }
  }
}
void fakemain() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(0);
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < (n + 2); ++i) {
      adj[i].clear();
      sz[i] = 0;
      for (int j = 0; j < (n + 2); ++j) {
        dp[i][j] =
            pair<long long, long long>(-(long long)1e16, -(long long)1e16);
      }
    }
    for (int j = 0; j < (2); ++j)
      for (int i = 1; i < (n + 1); ++i) {
        scanf("%d", &pp[j][i]);
      }
    for (int i = 0; i < (n - 1); ++i) {
      int x, y;
      scanf("%d%d", &x, &y);
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    solve(1);
    printf("%d\n", dp[1][m - 1].first + (dp[1][m - 1].second > 0 ? 1 : 0));
  }
}
int main() { fakemain(); }
