#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 3005;
vector<int> g[maxn];
int n, m, sz[maxn];
long long a[maxn], b[maxn];
pair<int, long long> f[maxn][maxn], dp[maxn];
void upd(pair<int, long long> &x, pair<int, long long> y) {
  if (x.first < y.first || (x.first == y.first && x.second < y.second)) x = y;
}
void dfs(int u, int fa) {
  sz[u] = 1;
  f[u][1] = pair<int, long long>(0, a[u]);
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 1; i <= sz[u] + sz[v]; ++i)
      dp[i] = pair<int, long long>(-1, 0);
    for (int i = 1; i <= sz[u]; ++i) {
      for (int j = 1; j <= sz[v]; ++j) {
        upd(dp[i + j], pair<int, long long>(
                           f[u][i].first + f[v][j].first + (f[v][j].second > 0),
                           f[u][i].second));
        upd(dp[i + j - 1],
            pair<int, long long>(f[u][i].first + f[v][j].first,
                                 f[u][i].second + f[v][j].second));
      }
    }
    sz[u] += sz[v];
    for (int i = 1; i <= sz[u]; ++i) f[u][i] = dp[i];
  }
}
int main() {
  int t, u, v;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) g[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) a[i] = b[i] - a[i];
    for (int i = 1; i < n; ++i) {
      scanf("%d%d", &u, &v);
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(1, 0);
    printf("%d\n", f[1][m].first + (f[1][m].second > 0));
  };
  return 0;
}
