#include <bits/stdc++.h>
using namespace std;
const long long INF = 3e18 + 7;
const long long maxn = 4e5 + 700;
const int M = 1e6 + 8;
const long long mod = 998244353;
const double eps = 1e-9;
const double PI = acos(-1);
template <typename T>
inline void read(T &a) {
  char c = getchar();
  T x = 0, f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  a = f * x;
}
long long n, m, p;
long long dp[3005][3005];
long long sp[3005][3005];
int sz[maxn];
long long t1[maxn], t2[maxn];
long long a[maxn], b[maxn];
vector<int> v[maxn];
void dfs(int u, int fa) {
  dp[u][1] = (b[u] - a[u]) > 0 ? 1 : 0;
  sp[u][1] = b[u] - a[u];
  sz[u] = 1;
  for (int e : v[u]) {
    if (e == fa) continue;
    dfs(e, u);
    for (int k = 1; k <= sz[u] + sz[e]; k++) t1[k] = 0, t2[k] = -INF;
    for (int k = 1; k <= sz[u]; k++) {
      for (int j = 1; j <= sz[e]; j++) {
        if (dp[u][k] + dp[e][j] > t1[k + j])
          t1[k + j] = dp[u][k] + dp[e][j], t2[k + j] = sp[u][k];
        else if (dp[u][k] + dp[e][j] == t1[k + j])
          t2[k + j] = max(t2[k + j], sp[u][k]);
        int tmpx = sp[u][k] > 0 ? 1 : 0, tmpy = sp[e][j] > 0 ? 1 : 0;
        long long tmp = dp[u][k] + dp[e][j] - tmpx - tmpy +
                        (sp[u][k] + sp[e][j] > 0 ? 1 : 0);
        if (t1[k + j - 1] < tmp)
          t1[k + j - 1] = tmp, t2[k + j - 1] = sp[u][k] + sp[e][j];
        else if (t1[k + j - 1] == tmp)
          t2[k + j - 1] = max(t2[k + j - 1], sp[u][k] + sp[e][j]);
      }
    }
    sz[u] += sz[e];
    for (int k = 0; k <= sz[u]; k++) dp[u][k] = t1[k], sp[u][k] = t2[k];
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    read(n);
    read(m);
    for (int i = 1; i <= n; i++) v[i].clear();
    for (int i = 1; i <= n; i++)
      for (int k = 1; k <= n; k++) dp[i][k] = 0, sp[i][k] = -INF;
    for (int i = 1; i <= n; i++) read(a[i]);
    for (int i = 1; i <= n; i++) read(b[i]);
    for (int i = 1; i <= n - 1; i++) {
      int x, y;
      read(x);
      read(y);
      v[x].push_back(y);
      v[y].push_back(x);
    }
    dfs(1, 1);
    printf("%lld\n", dp[1][m]);
    ;
  }
  return 0;
}
