#include <bits/stdc++.h>
using namespace std;
int n, t, m, a[100005], f[3005][3005], x, i, u, v;
long long g[3005][3005];
int head[3005], Next[6005], adj[6005], k, siz[100005];
void Push(int u, int v) {
  Next[++k] = head[u];
  head[u] = k;
  adj[k] = v;
}
void dfs(int i, int fa) {
  int j, k, l, s = 0;
  siz[i] = 1;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa) {
      dfs(adj[j], i);
      siz[i] += siz[adj[j]];
    }
  g[i][0] = a[i];
  f[i][0] = 0;
  for (j = head[i]; j != 0; j = Next[j])
    if (adj[j] != fa) {
      s += siz[adj[j]];
      for (k = min(s, m); k >= 0; --k) {
        int fs = -100000000;
        long long fg = -1000000000000ll;
        for (l = min(siz[adj[j]] - 1, k); l >= 0; --l) {
          if (fs <= f[i][k - l] + f[adj[j]][l]) {
            fs = f[i][k - l] + f[adj[j]][l];
            fg = max(fg, g[i][k - l] + g[adj[j]][l]);
          }
          if (l > 0)
            if (fs <= f[i][k - l] + f[adj[j]][l - 1] + (g[adj[j]][l - 1] > 0)) {
              fs = f[i][k - l] + f[adj[j]][l - 1] + (g[adj[j]][l - 1] > 0);
              fg = max(fg, g[i][k - l]);
            }
        }
        f[i][k] = fs;
        g[i][k] = fg;
      }
    }
}
int main() {
  scanf("%d", &t);
  while (t--) {
    memset(f, -1000000, sizeof(f));
    memset(g, -1000000, sizeof(g));
    scanf("%d %d", &n, &m);
    for (i = 1; i <= n; ++i) scanf("%d", &a[i]);
    for (i = 1; i <= n; ++i) {
      scanf("%d", &x);
      a[i] -= x;
    }
    memset(head, 0, sizeof(head));
    k = 0;
    for (i = 1; i < n; ++i) {
      scanf("%d %d", &u, &v);
      Push(u, v);
      Push(v, u);
    }
    dfs(1, 0);
    cout << f[1][m - 1] + (g[1][m - 1] > 0) << endl;
  }
}
