#include <bits/stdc++.h>
using namespace std;
int n, m, w[3010], b[3010], sz[3010];
vector<int> adj[3010];
vector<pair<int, long long> > dp[3010];
void update_dp(int u, int v) {
  vector<pair<int, long long> > ndp(dp[u].size() + dp[v].size() - 1,
                                    pair<int, long long>(-1, 0));
  for (int i = 1; i < dp[u].size(); i++) {
    for (int j = 1; j < dp[v].size(); j++) {
      pair<int, long long> tmp = pair<int, long long>(
          dp[u][i].first + dp[v][j].first, dp[u][i].second + dp[v][j].second);
      ndp[i + j - 1] = max(ndp[i + j - 1], tmp);
      tmp = pair<int, long long>(
          dp[u][i].first + dp[v][j].first + (dp[v][j].second > 0),
          dp[u][i].second);
      ndp[i + j] = max(ndp[i + j], tmp);
    }
  }
  dp[u] = ndp;
}
void dfs(int u, int par = 0) {
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == par) continue;
    dfs(v, u);
    update_dp(u, v);
  }
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
    }
    for (int i = 1; i <= n; i++) {
      scanf("%d", &w[i]);
    }
    for (int i = 0; i < n - 1; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    for (int i = 1; i <= n; i++) {
      dp[i].resize(2);
      dp[i][1] = pair<int, long long>(0, w[i] - b[i]);
    }
    dfs(1);
    int ans = dp[1][m].first + (dp[1][m].second > 0);
    printf("%d\n", ans);
    for (int i = 1; i <= n; i++) {
      adj[i].clear();
      dp[i].clear();
    }
  }
}
