#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const long long INF = 1e18;
long long f[N][N], g[N][N], Top[N][N], Top2[N][N];
int siz[N];
int b[N], w[N];
vector<int> e[N];
void dfs(int u, int fa) {
  siz[u] = 1;
  for (auto v : e[u]) {
    if (v == fa) continue;
    dfs(v, u);
    siz[u] += siz[v];
  }
  for (int i = 1; i <= siz[u]; i++) {
    f[u][i] = g[u][i] = 0;
    Top[u][i] = Top2[u][i] = -INF;
  }
  f[u][1] = 0;
  Top[u][1] = w[u];
  int tot = 1;
  for (auto v : e[u]) {
    if (v == fa) continue;
    for (int j = 1; j <= siz[v]; j++) {
      for (int k = 1; k <= tot; k++) {
        int add = (Top[v][j] > 0);
        if (f[v][j] + f[u][k] + add > g[u][j + k]) {
          g[u][j + k] = f[v][j] + f[u][k] + add;
          Top2[u][j + k] = Top[u][k];
        } else if (f[v][j] + f[u][k] + add == g[u][j + k]) {
          Top2[u][j + k] = max(Top2[u][j + k], Top[u][k]);
        }
        if (f[v][j] + f[u][k] > g[u][j + k - 1]) {
          g[u][j + k - 1] = f[v][j] + f[u][k];
          Top2[u][j + k - 1] = Top[u][k] + Top[v][j];
        } else if (f[v][j] + f[u][k] == g[u][j + k - 1]) {
          Top2[u][j + k - 1] = max(Top2[u][j + k - 1], Top[u][k] + Top[v][j]);
        }
      }
    }
    tot += siz[v];
    for (int j = 1; j <= tot; j++) {
      f[u][j] = g[u][j];
      Top[u][j] = Top2[u][j];
      g[u][j] = 0;
      Top2[u][j] = -INF;
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n, m;
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
      e[i].clear();
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &w[i]);
      w[i] -= b[i];
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      e[u].push_back(v);
      e[v].push_back(u);
    }
    dfs(1, 0);
    printf("%lld\n", f[1][m] + (Top[1][m] > 0));
  }
  return 0;
}
