#include <bits/stdc++.h>
using namespace std;
const int N = 3005;
const long long F = 1e15;
int hd[N], to[N], nx[N], tt;
void add(int u, int v) {
  nx[++tt] = hd[u];
  to[hd[u] = tt] = v;
}
int n, m, sz[N], f[N][N];
long long a[N], g[N][N];
void dfs(int u, int fa) {
  sz[u] = 1;
  for (int i = 0; i <= n; i++) f[u][i] = -N, g[u][i] = -F;
  f[u][0] = 0;
  g[u][0] = a[u];
  for (int e = hd[u]; e; e = nx[e])
    if (to[e] != fa) {
      int v = to[e], tf[N];
      long long tg[N];
      dfs(v, u);
      for (int i = 0; i <= sz[u] + sz[v]; i++) tf[i] = -N, tg[i] = -F;
      for (int i = min(sz[v], m); ~i; i--) {
        for (int j = min(sz[u], m); ~j; j--) {
          int x = f[v][i] + f[u][j];
          long long y = g[v][i] + g[u][j];
          if (x > tf[i + j])
            tf[i + j] = x, tg[i + j] = y;
          else if (x == tf[i + j])
            tg[i + j] = max(tg[i + j], y);
        }
      }
      sz[u] += sz[v];
      for (int i = 0; i <= sz[u]; i++) f[u][i] = tf[i], g[u][i] = tg[i];
    }
  for (int i = sz[u] - 1; ~i; i--) {
    int x = f[u][i] + (g[u][i] > 0ll);
    if (f[u][i + 1] < x)
      f[u][i + 1] = x, g[u][i + 1] = 0;
    else if (f[u][i + 1] == x)
      g[u][i] = max(g[u][i], 0ll);
  }
}
void work() {
  cin >> n >> m;
  tt = 0;
  memset(hd, 0, sizeof(hd));
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  for (int x, i = 1; i <= n; i++) scanf("%d", &x), a[i] = x - a[i];
  for (int u, v, i = 1; i < n; i++) scanf("%d%d", &u, &v), add(u, v), add(v, u);
  dfs(1, 0);
  cout << f[1][m] << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) work();
  return 0;
}
