#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAXN = 3030;
const ll INF = 1e18;
int N, M;
vector<int> adj[MAXN];
ll B[MAXN], W[MAXN];
int sz[MAXN];
map<int, ll> dp[MAXN][MAXN];
map<int, ll> ndp[MAXN];
void modify(map<int, ll> &dp, int x, ll val) {
  if (!dp.count(x)) {
    dp[x] = -INF;
  }
  dp[x] = max(dp[x], val);
}
void Dfs(int v, int p) {
  sz[v] = 1;
  for (int i = 0; i <= N; ++i) {
    dp[v][i] = {};
  }
  dp[v][0][0] = W[v] - B[v];
  for (int u : adj[v]) {
    if (u != p) {
      Dfs(u, v);
      for (int i = 0; i <= sz[v]; ++i) {
        for (auto p1 : dp[v][i]) {
          for (int j = 0; j <= sz[u]; ++j) {
            for (auto p2 : dp[u][j]) {
              modify(ndp[i + j], p1.first + p2.first, p1.second + p2.second);
            }
          }
        }
      }
      sz[v] += sz[u];
      for (int i = 0; i <= sz[v]; ++i) {
        dp[v][i] = move(ndp[i]);
        ndp[i] = {};
      }
    }
  }
  cerr << v << " " << sz[v] << "\n";
  if (v > 0) {
    for (int i = sz[v] - 1; i >= 0; --i) {
      for (auto p : dp[v][i]) {
        modify(dp[v][i + 1], p.first + (p.second > 0LL), 0);
      }
    }
    for (int i = 0; i <= sz[v]; ++i) {
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < N; ++i) {
      cin >> B[i];
    }
    for (int i = 0; i < N; ++i) {
      cin >> W[i];
    }
    for (int i = 0; i < N - 1; ++i) {
      int v, u;
      cin >> v >> u;
      --v, --u;
      adj[v].emplace_back(u);
      adj[u].emplace_back(v);
    }
    Dfs(0, -1);
    auto it = dp[0][M - 1].rbegin();
    cout << (it->first + (it->second > 0)) << "\n";
    for (int i = 0; i < N; ++i) {
      adj[i] = {};
    }
  }
}
