#include <bits/stdc++.h>
using namespace std;
const long long N = 3005, oo = 1e18;
long long n, m, a[N], subSize[N];
vector<long long> adj[N];
pair<long long, long long> tmp[N], dp[N][N];
pair<long long, long long> operator+(const pair<long long, long long> a,
                                     const pair<long long, long long> b) {
  return {a.first + b.first, a.second + b.second};
}
void dfs(long long u, long long pre) {
  subSize[u] = 1;
  dp[u][0] = {0, a[u]};
  for (long long v : adj[u]) {
    if (v == pre) continue;
    dfs(v, u);
    for (long long i = 0; i <= subSize[u]; ++i)
      if (dp[u][i].second != -oo) {
        for (long long j = 0; j <= subSize[v]; ++j) {
          pair<long long, long long> trans = dp[v][j];
          if (j > 0 && dp[v][j - 1].second > 0)
            trans = max(trans, {dp[v][j - 1].first + 1, 0});
          if (trans.second == oo) continue;
          tmp[i + j] = max(tmp[i + j], dp[u][i] + trans);
        }
      }
    subSize[u] += subSize[v];
    for (long long i = 0; i <= subSize[u]; ++i) {
      dp[u][i] = tmp[i];
      tmp[i] = {0, -oo};
    }
  }
  if (u != 1) {
    for (long long i = n; i >= 1; --i) {
      if (dp[u][i - 1].second > 0) {
        dp[u][i] = max(dp[u][i], {dp[u][i - 1].first + 1, 0});
      } else
        dp[u][i] = max(dp[u][i], {dp[u][i - 1].first, 0});
    }
  } else {
    for (long long i = n; i >= 1; --i) {
      if (dp[u][i - 1].second > 0) {
        dp[u][i] = {dp[u][i - 1].first + 1, 0};
      } else
        dp[u][i] = {dp[u][i - 1].first, 0};
    }
  }
}
void solve() {
  cin >> n >> m;
  tmp[0] = {0, -oo};
  for (long long i = 0; i <= n; ++i) {
    for (long long j = 0; j <= n; ++j) dp[i][j] = {0, -oo};
    tmp[i] = {0, -oo};
    a[i] = 0;
    subSize[i] = 0;
  }
  for (long long i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    a[i] -= x;
  }
  for (long long i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    a[i] += x;
    adj[i].clear();
  }
  for (long long i = 1; i < n; ++i) {
    long long u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1, -1);
  cout << dp[1][m].first << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long tc;
  cin >> tc;
  while (tc--) {
    solve();
  }
  return 0;
}
