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