#include <bits/stdc++.h>
using namespace std;
const int N = 3e3 + 50;
int T, n, m, w[N];
pair<int, long long> dp[N][N];
int sz[N];
vector<int> G[N];
void chkmx(pair<int, long long> &a, pair<int, long long> b) {
  if (a < b) a = b;
}
pair<int, long long> operator+(pair<int, long long> a, pair<int, long long> b) {
  return pair<int, long long>(a.first + b.first, a.second + b.second);
}
void dfs(int u, int f) {
  for (int i = 0; i <= n; i++) dp[u][i] = pair<int, long long>(-1e9, 0);
  dp[u][1] = pair<int, long long>(0, w[u]);
  sz[u] = 1;
  for (int v : G[u])
    if (v != f) {
      dfs(v, u);
      static pair<int, long long> tmp[N];
      for (int i = 0; i <= sz[u] + sz[v]; i++)
        tmp[i] = pair<int, long long>(-1e9, 0);
      for (int i = 0; i <= sz[u]; i++)
        for (int j = 0; j <= sz[v]; j++)
          chkmx(tmp[i + j],
                pair<int, long long>(
                    dp[u][i].first + dp[v][j].first + (dp[v][j].second > 0),
                    dp[u][i].second)),
              chkmx(tmp[i + j - 1], pair<int, long long>(dp[u][i] + dp[v][j]));
      sz[u] += sz[v];
      for (int i = 0; i <= sz[u]; i++) chkmx(dp[u][i], tmp[i]);
    }
}
void Main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 1, x; i <= n; i++) scanf("%d", &x), w[i] -= x;
  for (int i = 1, u, v; i < n; i++)
    scanf("%d%d", &u, &v), G[u].push_back(v), G[v].push_back(u);
  dfs(1, 0);
  cout << dp[1][m].first + (dp[1][m].second > 0) << '\n';
  for (int i = 1; i <= n; i++) G[i].clear();
}
int main() {
  cin >> T;
  while (T--) Main();
  return 0;
}
