#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 19;
const long long inf = 1e18;
long long n, m, t, a[N], b[N], w[N], sz[N];
vector<long long> g[N];
pair<long long, long long> mx[N], dp[N][N], val[N];
void dfssz(long long u, long long p = -1) {
  sz[u] = 1;
  mx[u] = {0, -1};
  for (long long to : g[u]) {
    if (p == to) continue;
    dfssz(to, u);
    sz[u] += sz[to];
    mx[u] = max(mx[u], {sz[to], to});
  }
}
void dfs(long long u, long long p = -1) {
  for (long long to : g[u])
    if (to != p) dfs(to, u);
  dp[u][1] = {0, a[u]};
  long long cursz = 1;
  for (long long to : g[u]) {
    if (to == p) continue;
    for (long long i = 1; i <= cursz + sz[to]; i++) val[i] = {0, -inf};
    for (long long i = 1; i <= cursz; i++)
      for (long long j = 1; j <= sz[to]; j++) {
        val[i + j] = max(val[i + j], {dp[u][i].first + dp[to][j].first +
                                          (long long)(dp[to][j].second > 0),
                                      dp[u][i].second});
        val[i + j - 1] =
            max(val[i + j - 1], {dp[u][i].first + dp[to][j].first,
                                 dp[u][i].second + dp[to][j].second});
      }
    cursz += sz[to];
    for (long long i = 1; i <= cursz; i++) dp[u][i] = val[i];
  }
}
int main() {
  scanf("%lld", &t);
  for (int tes = 1; tes <= t; tes++) {
    scanf("%lld %lld", &n, &m);
    for (int i = 1; i <= n; i++) scanf("%lld", &b[i]);
    for (int i = 1; i <= n; i++) scanf("%lld", &w[i]);
    for (int i = 1; i <= n; i++) a[i] = w[i] - b[i];
    for (int i = 1; i <= n; i++) g[i].clear();
    long long u, v;
    for (int i = 1; i < n; i++) {
      scanf("%lld %lld", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfssz(1);
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= n; j++) dp[i][j] = {0, -inf};
    dfs(1);
    cout << dp[1][m].first + (long long)(dp[1][m].second > 0) << "\n";
  }
  return 0;
}
