#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e3 + 10;
const int MOD = 998244353;
vector<int> ve[maxn];
int n, m, sz[maxn];
long long a[maxn];
pair<int, long long> f[maxn][maxn], g[maxn][maxn];
void dfs(int u, int fa) {
  sz[u] = 1;
  f[u][1] = make_pair(0, a[u]);
  for (auto v : ve[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 1; i <= sz[u] + sz[v]; i++) g[u][i] = make_pair(0, -1e18);
    for (int i = 1; i <= sz[u]; i++) {
      for (int j = 1; j <= sz[v]; j++) {
        g[u][i + j] = max(g[u][i + j], make_pair(f[u][i].first + f[v][j].first +
                                                     (f[v][j].second > 0),
                                                 f[u][i].second));
        g[u][i + j - 1] =
            max(g[u][i + j - 1], make_pair(f[u][i].first + f[v][j].first,
                                           f[v][j].second + f[u][i].second));
      }
    }
    sz[u] += sz[v];
    for (int i = 1; i <= sz[u]; i++) f[u][i] = g[u][i];
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
    for (int i = 1; i <= n; i++) {
      ve[i].clear();
      long long x;
      scanf("%lld", &x);
      a[i] = x - a[i];
    }
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      ve[x].push_back(y);
      ve[y].push_back(x);
    }
    dfs(1, -1);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
  }
  return 0;
}
