#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 7;
const long long LINF = INF * (long long)INF;
const int mod = INF;
const int N = 3005;
vector<int> g[N];
pair<int, long long> dp[2][N][N];
int w[N], b[N];
int n, m;
int sub[N];
void dfs(int u, int p = -1) {
  sub[u] = 1;
  vector<int> sons;
  for (auto v : g[u]) {
    if (v != p) {
      dfs(v, u);
      sub[u] += sub[v];
      sons.push_back(v);
    }
  }
  int total = 1;
  dp[0][u][1] = {0, w[u]};
  for (auto v : sons) {
    for (int i = total; i >= 1; i--)
      for (int j = sub[v]; j >= 1; j--) {
        dp[1][u][i + j] = max(
            dp[1][u][i + j],
            {dp[0][u][i].first + dp[0][v][j].first + (dp[0][v][j].second > 0),
             dp[0][u][i].second});
        dp[1][u][i + j - 1] =
            max(dp[1][u][i + j - 1], {dp[0][u][i].first + dp[0][v][j].first,
                                      dp[0][u][i].second + dp[0][v][j].second});
      }
    total += sub[v];
    for (int i = 0; i <= total; i++) {
      dp[0][u][i] = dp[1][u][i];
      dp[1][u][i] = {-INF, -LINF};
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int k = 0; k < 2; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j <= m; j++) dp[k][i][j] = {-INF, -LINF};
    for (int i = 0; i < n; i++) g[i].clear();
    for (int i = 0; i < n; i++) cin >> b[i];
    for (int i = 0; i < n; i++) {
      cin >> w[i];
      w[i] -= b[i];
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    dfs(0);
    cout << dp[0][0][m].first + (dp[0][0][m].second > 0) << endl;
  }
}
