#include <bits/stdc++.h>
using namespace std;
const int N = 3004;
const long long inf = -1e16 - 3;
int m, n;
pair<long long, long long> b[N];
long long a[N];
vector<int> adj[N];
int test;
int socon[N];
long long sum[N];
pair<long long, long long> dp[N][N];
pair<long long, long long> tmp[N];
pair<long long, long long> chekmax(pair<long long, long long> cur,
                                   pair<long long, long long> a,
                                   pair<long long, long long> b, int tp) {
  if (tp == 1) {
    return max(cur, {a.first + b.first, a.second + b.second});
  } else {
    return max(cur, {a.first + b.first + (b.second > 0), a.second});
  }
}
void dfs(int i, int j) {
  socon[i] = 1;
  sum[i] = a[i];
  dp[i][1] = {0, a[i]};
  for (int u : adj[i]) {
    if (u == j) continue;
    dfs(u, i);
    for (int t = 0; t <= m; t++) tmp[t] = {inf, inf};
    sum[i] += sum[u];
    for (int t = 1; t <= socon[i]; t++)
      for (int k = 1; k <= socon[u]; k++) {
        if (t + k <= m) tmp[t + k] = chekmax(tmp[t + k], dp[i][t], dp[u][k], 0);
        if (t + k - 1 <= m)
          tmp[t + k - 1] = chekmax(tmp[t + k - 1], dp[i][t], dp[u][k], 1);
      }
    socon[i] += socon[u];
    for (int t = 1; t <= socon[i]; t++) dp[i][t] = tmp[t];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> test;
  while (test--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> b[i].first;
    for (int i = 1; i <= n; i++) cin >> b[i].second;
    for (int i = 1; i <= n; i++)
      a[i] = b[i].second - b[i].first, adj[i].clear(), socon[i] = 0;
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) dp[i][j] = {0, inf};
    dfs(1, 0);
    cout << dp[1][m].first + (dp[1][m].second > 0) << '\n';
  }
}
