#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const ll MOD = 1e9 + 7;
const double PI = acos(-1);
const int INF = 0x3f3f3f3f;
const int NINF = 0x3f3f3f40;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll NINFLL = 0x3f3f3f3f3f3f3f40;
const int mxN = 3001;
int t, n, m;
vector<int> adj[mxN];
pair<ll, ll> dp[mxN][mxN];
int sz[mxN];
ll arr[mxN];
ll ww[mxN];
ll bb[mxN];
pair<ll, ll> save[mxN];
void solve(int u, int p) {
  sz[u] = 1;
  dp[u][1] = {0, arr[u]};
  for (int v : adj[u]) {
    if (v == p) continue;
    solve(v, u);
    for (int i = (0); i < (sz[u] + sz[v] + 1); ++i) {
      save[i] = {-1, 0};
    }
    for (int i = (1); i < (sz[u] + 1); ++i) {
      for (int j = (1); j < (sz[v] + 1); ++j) {
        save[i + j] = max(save[i + j], {dp[u][i].first + dp[v][j].first +
                                            (dp[v][j].second > 0),
                                        dp[u][i].second});
        save[i + j - 1] =
            max(save[i + j - 1], {dp[u][i].first + dp[v][j].first,
                                  dp[u][i].second + dp[v][j].second});
      }
    }
    for (int i = (0); i < (sz[u] + sz[v] + 1); ++i) {
      dp[u][i] = save[i];
    }
    sz[u] += sz[v];
  }
}
int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = (0); i < (mxN); ++i) {
      adj[i].clear();
    }
    for (int i = (0); i < (n); ++i) {
      cin >> bb[i];
    }
    for (int i = (0); i < (n); ++i) {
      cin >> ww[i];
      arr[i] = ww[i] - bb[i];
    }
    int a, b;
    for (int i = (0); i < (n - 1); ++i) {
      cin >> a >> b;
      a--;
      b--;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    solve(0, 0);
    cout << (dp[0][m].first + (dp[0][m].second > 0)) << '\n';
  }
  return 0;
}
