#include <bits/stdc++.h>
using namespace std;
const int N = 3e2;
mt19937 rng(std::chrono::system_clock::now().time_since_epoch().count());
int n, m, sz[N];
pair<int, long long> dp[N][N];
long long val[N];
vector<vector<int>> g;
void fix(pair<int, long long>& a, pair<int, long long> b) {
  if (b.first > a.first) a = b;
  if (b.first == a.first) a.second = min(a.second, b.second);
}
void dfs(int u, int p) {
  sz[u] = 1;
  for (auto v : g[u])
    if (v != p) {
      dfs(v, u);
      val[u] += val[v];
      int to = min(max(0, m - sz[u]), sz[v]);
      for (int i = 0; i <= sz[u]; i++)
        for (int j = 0; j <= to; j++) {
          int x = dp[u][i].first + dp[v][j].first;
          long long y = dp[u][i].second + dp[v][j].second;
          fix(dp[u][i + j], make_pair(x, y));
          x += val[v] - dp[v][j].second > 0;
          y = dp[u][i].second + val[v];
          fix(dp[u][i + j + 1], make_pair(x, y));
        }
      sz[u] += sz[v];
    }
  dp[u][0] = {0, val[u]};
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    g.clear();
    g.resize(n);
    for (int i = 0; i < n; i++) scanf("%lld", val + i);
    for (int i = 0, a; i < n; i++) {
      scanf("%d", &a);
      val[i] = a - val[i];
    }
    for (int i = 1, a, b; i < n; i++) {
      scanf("%d%d", &a, &b);
      g[--a].push_back(--b);
      g[b].push_back(a);
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j <= m; j++) dp[i][j] = {0, 0};
    dfs(0, -1);
    printf("%d\n", dp[0][m - 1].first + (val[0] - dp[0][m - 1].second > 0));
  }
}
