#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
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;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 3001;
vector<vector<int> > graph;
long long V[MX];
vector<pair<long long, long long> > dp[MX];
void dfs(int v, int p) {
  dp[v].push_back({0, V[v]});
  for (auto& nxt : graph[v]) {
    if (nxt == p) continue;
    dfs(nxt, v);
    vector<pair<long long, long long> > nd;
    for (int i = 0; i < ((int)(dp[v]).size() + (int)(dp[nxt]).size() - 1); i++)
      nd.push_back({0, -1e18});
    for (int i = 0; i < ((int)(dp[v]).size()); i++) {
      for (int j = 0; j < ((int)(dp[nxt]).size()); j++) {
        pair<long long, long long> A = dp[v][i];
        pair<long long, long long> B = dp[nxt][j];
        pair<long long, long long> res = {A.first + B.first,
                                          A.second + B.second};
        ckmax(nd[i + j], res);
      }
    }
    dp[v] = nd;
  }
  dp[v].push_back({0, -1e18});
  for (int i = ((int)(dp[v]).size() - 1) - 1; i >= 0; i--) {
    ckmax(dp[v][i + 1], {dp[v][i].first + (dp[v][i].second > 0 ? 1 : 0), 0});
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    graph.clear();
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < (N); i++) {
      graph.push_back(vector<int>());
    }
    for (int i = 0; i < (N); i++) {
      cin >> V[i];
    }
    for (int i = 0; i < (N); i++) {
      long long cur;
      cin >> cur;
      V[i] = cur - V[i];
    }
    for (int i = 0; i < (N - 1); i++) {
      int A, B;
      cin >> A >> B;
      A--;
      B--;
      graph[A].push_back(B);
      graph[B].push_back(A);
    }
    for (int i = 0; i < (N); i++) dp[i].clear();
    dfs(0, -1);
    long long res = dp[0][M - 1].first;
    if (dp[0][M - 1].second > 0) res++;
    cout << res << nl;
  }
  return 0;
}
