#include <bits/stdc++.h>
const double PI = acos(-1.0);
const int DIR = 4;
const int X[] = {1, 0, -1, 0};
const int Y[] = {0, 1, 0, -1};
const int N = 3005;
const long long INF = (long long)1e18 + 228;
using namespace std;
int n, m, a[N], sz[N];
pair<int, long long> dp[N][N], nw[N][N];
vector<int> g[N];
bool cmp(int x, int y) { return sz[x] > sz[y]; }
void dfs(int v, int pr) {
  sz[v] = 1;
  dp[v][1] = {0, a[v]};
  for (auto to : g[v]) {
    if (to == pr) continue;
    dfs(to, v);
  }
  for (auto to : g[v]) {
    if (to == pr) continue;
    for (int i = 1; i <= min(sz[v] + sz[to], m); i++) nw[v][i] = {0, -INF};
    for (int i = 1; i <= min(sz[to], m); i++) {
      for (int j = 1; j <= sz[v] && j + i - 1 <= m; j++) {
        nw[v][i + j] =
            max(nw[v][i + j], make_pair(dp[v][j].first + dp[to][i].first +
                                            bool(dp[to][i].second > 0),
                                        dp[v][j].second));
        nw[v][i + j - 1] = max(nw[v][i + j - 1],
                               make_pair(dp[v][j].first + dp[to][i].first,
                                         dp[to][i].second + dp[v][j].second));
      }
    }
    for (int i = 1; i <= min(sz[v] + sz[to], m); i++) dp[v][i] = nw[v][i];
    sz[v] += sz[to];
  }
}
void solve() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[i] = x - a[i];
  }
  for (int i = 1; i <= n; i++) g[i].clear();
  for (int i = 1; i <= n - 1; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    g[v].push_back(u);
    g[u].push_back(v);
  }
  dfs(1, -1);
  cout << dp[1][m].first + bool(dp[1][m].second > 0) << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
