#include <bits/stdc++.h>
using namespace std;
mt19937 rng(static_cast<unsigned int>(
    chrono::steady_clock::now().time_since_epoch().count()));
template <typename num_t>
inline void add_mod(num_t& a, const long long& b, const int& m) {
  a = (a + b) % m;
  if (a < 0) a += m;
}
template <typename num_t>
inline bool update_max(num_t& a, const num_t& b) {
  return a < b ? a = b, true : false;
}
template <typename num_t>
inline bool update_min(num_t& a, const num_t& b) {
  return a > b ? a = b, true : false;
}
template <typename num_t>
num_t gcd(const num_t& lhs, const num_t& rhs) {
  return !lhs ? rhs : gcd(rhs % lhs, lhs);
}
template <typename num_t>
num_t lcm(const num_t& lhs, const num_t& rhs) {
  return lhs / ::gcd(lhs, rhs) * rhs;
}
template <typename num_t>
num_t pw(num_t n, num_t k, const num_t& mod) {
  if (k == -1) k = mod - 2;
  num_t res = 1;
  for (; k > 0; k >>= 1) {
    if (k & 1) res = 1ll * res * n % mod;
    n = 1ll * n * n % mod;
  }
  return res % mod;
}
const int inf = 1e9 + 7;
const int mod = 998244353;
const long long ll_inf = (long long)inf * inf * 9 + 7;
const int maxn = 3000 + 7;
vector<int> adj[maxn];
int score[maxn];
int n, m;
int dp[maxn][maxn];
int g[maxn][maxn];
long long max_value[maxn][maxn];
int f[maxn];
void dfs(int u, int root) {
  f[u] = 1;
  for (int j = (0), _b = (m + 1); j < _b; ++j) {
    dp[u][j] = -inf;
    max_value[u][j] = -ll_inf;
    g[u][j] = -inf;
  }
  g[u][1] = (score[u] > 0);
  dp[u][0] = 0;
  max_value[u][0] = score[u];
  for (int v : adj[u])
    if (v != root) {
      dfs(v, u);
      static int has[maxn];
      static int temp[maxn];
      static long long value[maxn];
      for (int j = (0), _b = (min(m, f[u] + f[v]) + 1); j < _b; ++j) {
        has[j] = -inf;
        value[j] = -ll_inf;
        temp[j] = -inf;
      }
      auto update = [&](int comp, int mx, long long sum) {
        if (has[comp] < mx) {
          has[comp] = mx;
          value[comp] = sum;
        } else if (has[comp] == mx) {
          update_max(value[comp], sum);
        }
      };
      for (int p = (0), _b = (min(f[v], m) + 1); p < _b; ++p)
        for (int q = (0), _b = (min(f[u], m) + 1); q < _b; ++q)
          if (p + q <= m) {
            long long sum = max_value[v][p] + max_value[u][q];
            int cnt = dp[v][p] + dp[u][q];
            update(p + q, cnt, sum);
            update(p + q, dp[u][q] + g[v][p], max_value[u][q]);
            update_max(temp[p + q], g[v][p] + g[u][q]);
            if (p + q + 1 <= m) {
              update_max(temp[p + q + 1], cnt + (sum > 0));
            }
          }
      for (int j = (0), _b = (min(m, f[u] + f[v]) + 1); j < _b; ++j) {
        dp[u][j] = has[j];
        max_value[u][j] = value[j];
        g[u][j] = temp[j];
        if (j > 0)
          update_max(g[u][j], dp[u][j - 1] + (max_value[u][j - 1] > 0));
      }
      f[u] += f[v];
    }
}
void solve() {
  int test;
  cin >> test;
  while (test-- > 0) {
    cin >> n >> m;
    for (int i = (0), _b = (n); i < _b; ++i) {
      score[i] = 0;
      adj[i].clear();
    }
    for (int i = (0), _b = (n); i < _b; ++i) {
      int u;
      cin >> u;
      score[i] -= u;
    }
    for (int i = (0), _b = (n); i < _b; ++i) {
      int u;
      cin >> u;
      score[i] += u;
    }
    for (int i = (1), _b = (n); i < _b; ++i) {
      int u, v;
      cin >> u >> v;
      --u;
      --v;
      adj[u].push_back(v);
      adj[v].push_back(u);
    }
    dfs(0, -1);
    cout << g[0][m] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  const bool multiple_test = false;
  int test = 1;
  if (multiple_test) cin >> test;
  for (int i = 0; i < test; ++i) {
    solve();
  }
}
