#include <bits/stdc++.h>
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int MAX_N = 3030;
int n, m;
long long weight[MAX_N];
vector<int> adj[MAX_N];
vector<int> ch[MAX_N];
pair<int, long long> dp[MAX_N][MAX_N];
int subsz[MAX_N];
void dfs(int u, int p) {
  for (int v : adj[u])
    if (v != p) {
      dfs(v, u);
      ch[u].push_back(v);
    }
}
int get_subsz(int u) {
  subsz[u] = 1;
  for (int v : ch[u]) subsz[u] += get_subsz(v);
  return subsz[u];
}
void solve(int u) {
  dp[u][0] = make_pair(0, weight[u]);
  int cnt = 0;
  for (int v : ch[u]) {
    solve(v);
    vector<pair<int, long long>> dpori(cnt + 1);
    for (int i = 0; i < cnt + 1; i++) {
      dpori[i] = dp[u][i];
      dp[u][i] = make_pair(-1, -1);
    }
    for (int regionsInChild = 0; regionsInChild < subsz[v]; regionsInChild++) {
      for (int regionsHere = 0; regionsHere <= cnt; regionsHere++) {
        pair<int, long long> child = dp[v][regionsInChild];
        pair<int, long long> here = dpori[regionsHere];
        ckmax(dp[u][regionsInChild + regionsHere + 1],
              make_pair(child.first + here.first + (child.second > 0),
                        here.second));
        ckmax(dp[u][regionsInChild + regionsHere],
              make_pair(child.first + here.first, child.second + here.second));
      }
    }
    cnt += subsz[v];
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      weight[i] = 0;
      adj[i].clear();
      ch[i].clear();
      subsz[i] = 0;
      for (int j = 0; j < n + 1; j++) dp[i][j] = make_pair(-1, -1);
    }
    for (int i = 0; i < n; i++) cin >> weight[i];
    for (int i = 0; i < n; i++) {
      long long x;
      cin >> x;
      weight[i] = x - weight[i];
    }
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      cin >> u >> v;
      u--;
      v--;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(0, -1);
    get_subsz(0);
    solve(0);
    cout << dp[0][m - 1].first + (dp[0][m - 1].second > 0) << "\n";
  }
}
