#include <bits/stdc++.h>
inline long long rd() {
  long long _x = 0;
  int _ch = getchar(), _f = 1;
  for (; !isdigit(_ch) && (_ch != '-') && (_ch != EOF); _ch = getchar())
    ;
  if (_ch == '-') {
    _f = 0;
    _ch = getchar();
  }
  for (; isdigit(_ch); _ch = getchar()) _x = _x * 10 + _ch - '0';
  return _f ? _x : -_x;
}
void write(long long _x) {
  if (_x >= 10)
    write(_x / 10), putchar(_x % 10 + '0');
  else
    putchar(_x + '0');
}
inline void wrt(long long _x, char _p) {
  if (_x < 0) putchar('-'), _x = -_x;
  write(_x);
  if (_p) putchar(_p);
}
int n, m, T;
int w[3005], b[3005], a[3005];
std::vector<int> G[3005];
int sz[3005];
std::pair<int, long long> dp[3005][3005];
std::pair<int, long long> operator+(std::pair<int, long long> A,
                                    std::pair<int, long long> B) {
  return std::make_pair(A.first + B.first, A.second + B.second);
}
void dfs(int u, int fa) {
  sz[u] = 0;
  for (auto i : G[u])
    if (i != fa) {
      dfs(i, u);
      for (int j = sz[u] + 1; j <= sz[u] + sz[i]; j++)
        dp[u][j] = std::make_pair(0, -10000000000000000);
      if (sz[u] == 0) {
        for (int j = 0; j <= sz[i]; j++) {
          dp[u][j] = dp[i][j];
        }
        sz[u] += sz[i];
        continue;
      }
      for (int j = sz[u]; j >= 0; j--) {
        for (int k = 0; k <= sz[i]; k++) {
          dp[u][j + k] = std::max(dp[u][j + k], dp[u][j] + dp[i][k]);
        }
      }
      sz[u] += sz[i];
    }
  if (sz[u] == 0) {
    sz[u] = 1;
    dp[u][0] = std::make_pair(0, a[u]);
    dp[u][1] = std::make_pair(a[u] > 0, 0);
    return;
  }
  sz[u]++;
  for (int i = 0; i <= sz[u]; i++) {
    dp[u][i].second += a[u];
  }
  if (u == 1) {
    for (int i = sz[u] - 1; i >= 0; i--) {
      if (dp[u][i].second > 0) {
        dp[u][i + 1] = std::make_pair(dp[u][i].first + 1, 0ll);
      } else {
        dp[u][i + 1] = std::make_pair(dp[u][i].first, 0ll);
      }
    }
    return;
  }
  for (int i = sz[u] - 1; i >= 0; i--) {
    if (dp[u][i].second > 0) {
      dp[u][i + 1] =
          std::max(dp[u][i + 1], std::make_pair(dp[u][i].first + 1, 0ll));
    } else {
      dp[u][i + 1] =
          std::max(dp[u][i + 1], std::make_pair(dp[u][i].first, 0ll));
    }
  }
}
int main() {
  T = rd();
  while (T--) {
    n = rd(), m = rd();
    for (int i = 1; i <= n; i++) w[i] = rd();
    for (int i = 1; i <= n; i++) b[i] = rd();
    for (int i = 1; i <= n; i++) a[i] = b[i] - w[i];
    for (int i = 2; i <= n; i++) {
      int x = rd(), y = rd();
      G[x].push_back(y), G[y].push_back(x);
    }
    dfs(1, 1);
    wrt(dp[1][m].first, '\n');
    for (int i = 1; i <= n; i++) G[i].clear();
  }
}
