#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
const int maxn = 3333;
long long b[maxn], w[maxn];
vector<int> G[maxn];
int sz[maxn];
pair<int, long long> f[maxn][maxn], cf[maxn];
void dfs(int x, int fa) {
  sz[x] = 1, f[x][1] = pair<int, long long>(0, w[x]);
  for (int i = 0; i < G[x].size(); ++i) {
    int y = G[x][i];
    if (y == fa) continue;
    dfs(y, x);
    for (int j = 1; j <= sz[x] + sz[y]; ++j)
      cf[j] = pair<int, long long>(0, -inf);
    for (int j = 1; j <= sz[x]; ++j) {
      for (int k = 1; k <= sz[y]; ++k) {
        cf[j + k] =
            max(cf[j + k], pair<int, long long>(f[x][j].first + f[y][k].first +
                                                    (f[y][k].second > 0),
                                                f[x][j].second));
        cf[j + k - 1] =
            max(cf[j + k - 1],
                pair<int, long long>(f[x][j].first + f[y][k].first,
                                     f[x][j].second + f[y][k].second));
      }
    }
    sz[x] += sz[y];
    for (int j = 1; j <= sz[x]; ++j) f[x][j] = cf[j];
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%lld", b + i), G[i].clear();
    for (int i = 1; i <= n; ++i) scanf("%lld", w + i), w[i] -= b[i];
    for (int i = 1; i < n; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      G[u].push_back(v);
      G[v].push_back(u);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
  }
  return 0;
}
