#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
int n, m, siz[maxn], f[maxn][maxn];
long long a[maxn], b[maxn], g[maxn][maxn], s[maxn], t[maxn];
vector<int> e[maxn];
void dfs(int x, int ff) {
  f[x][0] = 0, g[x][0] = b[x] - a[x], siz[x] = 1;
  for (auto y : e[x])
    if (y != ff) {
      dfs(y, x);
      for (int i = 0; i <= siz[x] + siz[y]; i++)
        s[i] = -1e9, t[i] = -(1ll << 50);
      for (int i = siz[x]; i >= 0; i--)
        for (int j = siz[y]; j >= 0; j--)
          if (s[i + j] < f[x][i] + f[y][j]) {
            s[i + j] = f[x][i] + f[y][j];
            t[i + j] = g[x][i] + g[y][j];
          } else if (s[i + j] == f[x][i] + f[y][j] &&
                     t[i + j] < g[x][i] + g[y][j])
            t[i + j] = g[x][i] + g[y][j];
      siz[x] += siz[y];
      for (int i = 0; i <= siz[x]; i++) f[x][i] = s[i], g[x][i] = t[i];
    }
  for (int i = siz[x] - 1; i >= 0; i--) {
    int t = (g[x][i] > 0) ? 1 : 0;
    if (f[x][i + 1] < f[x][i] + t)
      f[x][i + 1] = f[x][i] + t, g[x][i + 1] = 0;
    else if (f[x][i + 1] == f[x][i] + t && g[x][i + 1] < 0)
      g[x][i + 1] = 0;
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) e[i].clear();
    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++)
      for (int j = 0; j <= n; j++) f[i][j] = -1e9, g[i][j] = -(1ll << 50);
    int x, y;
    for (int i = 1; i < n; i++) {
      scanf("%d%d", &x, &y);
      e[x].push_back(y);
      e[y].push_back(x);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m]);
  }
  return 0;
}
