#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/STACK:2000000")
using namespace std;
template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
  static_assert(D >= 1, "Vector dimension must be greater than zero!");
  template <typename... Args>
  Vec(int n = 0, Args... args)
      : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};
template <typename T>
struct Vec<1, T> : public vector<T> {
  Vec(int n = 0, T val = T()) : vector<T>(n, val) {}
};
using ll = long long;
using db = long double;
using ii = pair<int, int>;
const int N = 2e5 + 5, LG = 19, MOD = 1e9 + 7;
const int SQ = 320;
const long double EPS = 1e-7;
int n, m, x;
vector<int> adj[3005];
ll val[3005];
pair<int, ll> dp[3005][3005];
int sz[N];
void dfs(int node, int par) {
  dp[node][0] = make_pair(0, val[node]);
  sz[node] = 1;
  for (auto child : adj[node])
    if (child != par) {
      dfs(child, node);
      vector<pair<int, ll>> tmp(sz[node] + sz[child] + 1, make_pair(-1, -1));
      for (int k = 0; k < sz[node]; k++)
        for (int k2 = 0; k2 < sz[child]; k2++) {
          tmp[k + k2] =
              max(tmp[k + k2],
                  make_pair(dp[node][k].first + dp[child][k2].first,
                            dp[node][k].second + dp[child][k2].second));
          tmp[k + k2 + 1] =
              max(tmp[k + k2 + 1],
                  make_pair(dp[node][k].first + dp[child][k2].first +
                                (dp[child][k2].second > 0),
                            dp[node][k].second));
        }
      for (int i = 0; i < tmp.size(); i++) dp[node][i] = tmp[i];
      sz[node] += sz[child];
    }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i < n + 1; i++) {
      cin >> val[i];
      adj[i].clear();
    }
    for (int i = 1; i < n + 1; i++) {
      cin >> x;
      val[i] = x - val[i];
    }
    for (int i = 1; i < n; i++) {
      int u, v;
      cin >> u >> v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(1, 1);
    cout << dp[1][m - 1].first + (dp[1][m - 1].second > 0) << endl;
  }
  return 0;
}
