#include <bits/stdc++.h>
const int N = 3050;
const long long inf = 1e17;
using namespace std;
int n, m, e, ter[N], nxt[N], lnk[N], val[N], sz[N];
struct node {
  int Cnt;
  long long Val;
  node() {}
  node(int _Cnt, long long _Val) {
    Cnt = _Cnt;
    Val = _Val;
  }
  bool friend operator<(node a, node b) {
    if (a.Cnt < b.Cnt) return true;
    if (a.Cnt > b.Cnt) return false;
    return a.Val < b.Val;
  }
} f[N][N], tmp[N];
node operator+(node a, node b) { return node(a.Cnt + b.Cnt, a.Val + b.Val); }
void add(int x, int y) { ter[++e] = y, nxt[e] = lnk[x], lnk[x] = e; }
void dfs(int p, int las) {
  sz[p] = 1;
  for (int i = 1; i <= m; ++i) f[p][i] = node(-n, -inf);
  f[p][0] = node(0, val[p]);
  for (int i = lnk[p]; i; i = nxt[i])
    if (ter[i] != las) {
      int v = ter[i];
      dfs(v, p);
      for (int k = 0; k <= sz[p]; ++k) tmp[k] = node(-n, -inf);
      for (int k = sz[p]; k >= 0; --k)
        for (int j = 0; j <= sz[v]; ++j) {
          tmp[k + j] = max(tmp[k + j], f[v][j] + f[p][k]);
        }
      sz[p] += sz[v];
      for (int k = 0; k <= sz[p]; ++k) f[p][k] = tmp[k];
    }
  if (p == 1) {
    for (int i = m - 1; i >= 0; --i) {
      f[p][i + 1] = node(f[p][i].Cnt + (f[p][i].Val > 0LL), 0);
    }
  } else {
    for (int i = m - 1; i >= 0; --i)
      f[p][i + 1] =
          max(f[p][i + 1], node(f[p][i].Cnt + (f[p][i].Val > 0LL), 0));
  }
}
void Solve() {
  for (int i = 1; i <= e; ++i) nxt[i] = 0;
  for (int i = 1; i <= n; ++i) lnk[i] = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++i) scanf("%d", &val[i]);
  int x, y;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    val[i] = x - val[i];
  }
  for (int i = 1; i <= n - 1; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  printf("%d\n", f[1][m].Cnt);
}
int main() {
  int T;
  scanf("%d", &T);
  for (; T--;) {
    Solve();
  }
  return 0;
}
