#include <bits/stdc++.h>
using namespace std;
using DO = double;
using LL = long long;
using VI = vector<int>;
using pii = pair<int, LL>;
const int N = 3030;
int sz[N];
int w[N];
int flag[N];
VI adj[N];
void dfs(int u) {
  flag[u] = 1;
  sz[u] = 1;
  for (auto v : adj[u]) {
    if (flag[v]) continue;
    dfs(v);
    sz[u] += sz[v];
  }
  int mx = 0, id = 0;
  for (auto v : adj[u]) {
    if (flag[v]) continue;
    if (sz[v] > mx) {
      mx = sz[v];
      id = v;
    }
  }
  if (id) {
    for (int i = 0; i < adj[u].size(); i++)
      if (adj[u][i] == id) {
        swap(adj[u][i], adj[u][0]);
        break;
      }
  }
}
pii dp[N][N];
int n, m;
void rdfs(int u) {
  flag[u] = 2;
  int cnt = 1;
  for (int i = 1; i <= sz[u]; i++) {
    dp[u][i] = pii(0, 0);
  }
  for (auto v : adj[u]) {
    if (flag[v] == 2) continue;
    rdfs(v);
    if (cnt == 1) {
      for (int i = 2; i <= sz[v] + 1; i++) {
        dp[u][i] = pii(dp[v][i - 1].first + (dp[v][i - 1].second > 0), w[u]);
      }
      dp[u][1] = pii(0, dp[v][1].second + w[u]);
      for (int i = 2; i <= sz[v]; i++) {
        dp[u][i] = max(dp[u][i], pii(dp[v][i].first, dp[v][i].second + w[u]));
      }
    } else {
      for (int i = cnt; i >= 1; i--) {
        for (int j = sz[v]; j >= 1; j--) {
          dp[u][i + j] = max(dp[u][i + j], pii(dp[u][i].first + dp[v][j].first +
                                                   (dp[v][j].second > 0),
                                               dp[u][i].second));
          dp[u][i + j - 1] =
              max(dp[u][i + j], pii(dp[u][i].first + dp[v][j].first,
                                    dp[u][i].second + dp[v][j].second));
        }
      }
    }
    cnt += sz[v];
  }
  if (sz[u] == 1) {
    dp[u][1] = pii(0, w[u]);
  }
}
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", w + i);
    flag[i] = 0;
  }
  for (int i = 1, j; i <= n; i++) {
    scanf("%d", &j);
    w[i] = j - w[i];
  }
  for (int i = 1, u, v; i < n; i++) {
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  rdfs(1);
  printf("%d\n", dp[1][m].first + (dp[1][m].second > 0));
  for (int i = 1; i <= n; i++) {
    adj[i].clear();
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    solve();
  }
  return 0;
}
