#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T& x) {
  T data = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    data = (data << 3) + (data << 1) + ch - '0';
    ch = getchar();
  }
  x = f * data;
}
template <typename T, typename... Args>
inline void read(T& t, Args&... args) {
  read(t);
  read(args...);
}
const int inf = 0x3f3f3f3f;
const long long linf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;
const int maxn = 3e3 + 9;
const long long mod = 998244353;
pair<int, long long> operator+(pair<int, long long> a, pair<int, long long> b) {
  return make_pair(a.first + b.first, a.second + b.second);
}
int n, m, a[maxn], b[maxn];
vector<int> g[maxn];
pair<int, long long> dp[maxn][maxn], tmp[maxn];
int sz[maxn];
pair<int, long long> calc(pair<int, long long> x) {
  return make_pair(x.first + (x.second > 0), 0);
}
void dfs(int u, int fa) {
  dp[u][1] = make_pair(0, b[u] - a[u]);
  sz[u] = 1;
  for (int v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    for (int i = 0; i <= n; ++i) tmp[i] = make_pair(-1, 0LL);
    for (int i = 1; i <= sz[u]; ++i) {
      for (int j = 1; j <= sz[v]; ++j) {
        tmp[i + j] = max(tmp[i + j], dp[u][i] + calc(dp[v][j]));
        tmp[i + j - 1] = max(tmp[i + j - 1], dp[u][i] + dp[v][j]);
      }
    }
    for (int i = 0; i <= m; ++i) {
      dp[u][i] = tmp[i];
    }
    sz[u] += sz[v];
  }
}
signed main() {
  int T;
  read(T);
  while (T--) {
    read(n, m);
    for (int i = 1; i <= n; ++i) read(a[i]);
    for (int i = 1; i <= n; ++i) read(b[i]);
    for (int i = 1, u, v; i < n; ++i) {
      read(u, v);
      g[u].push_back(v), g[v].push_back(u);
    }
    dfs(1, 0);
    int ans = calc(dp[1][m]).first;
    cout << ans << '\n';
    for (int i = 1; i <= n; ++i) g[i].clear();
  }
  return 0;
}
