#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)3e3 + 5;
const long long INF = (long long)1e15;
pair<int, long long> dp[MAXN][MAXN];
vector<int> adj[MAXN];
int arr[MAXN];
int sub[MAXN];
int n, m;
void dfs(int v, int pr = -1) {
  fill(dp[v], dp[v] + n + 1, make_pair(-n, -INF));
  dp[v][0] = make_pair(0, 0);
  sub[v] = 1;
  for (int to : adj[v]) {
    if (to == pr) {
      continue;
    }
    dfs(to, v);
  }
  vector<pair<int, long long> > ndp(n + 5, make_pair(-n, -INF));
  for (int to : adj[v]) {
    if (to == pr) {
      continue;
    }
    for (int i = 0; i <= sub[v] + sub[to] + 3; ++i) {
      ndp[i] = make_pair(-n, -INF);
    }
    for (int i = sub[v]; i >= 0; --i) {
      for (int j = sub[to]; j >= 0; --j) {
        if (dp[v][i].second == -INF || dp[to][j].second == -INF ||
            dp[v][i].first < 0 || dp[to][j].first < 0) {
          continue;
        }
        if (dp[to][j].second > 0) {
          ndp[i + j + 1] = max(
              ndp[i + j + 1],
              make_pair(dp[v][i].first + dp[to][j].first + 1, dp[v][i].second));
        } else {
          ndp[i + j + 1] =
              max(ndp[i + j + 1],
                  make_pair(dp[v][i].first + dp[to][j].first, dp[v][i].second));
        }
        ndp[i + j] =
            max(ndp[i + j], make_pair(dp[v][i].first + dp[to][j].first,
                                      dp[v][i].second + dp[to][j].second));
      }
    }
    for (int j = 0; j < n; ++j) {
      dp[v][j] = ndp[j];
    }
    sub[v] += sub[to];
  }
  for (int i = 0; i < n; ++i) {
    if (dp[v][i].second != -INF) {
      dp[v][i].second += arr[v];
    }
  }
}
void solve() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) {
    adj[i].clear();
    arr[i] = 0;
  }
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    arr[i] = -x;
  }
  for (int i = 1, x; i <= n; ++i) {
    scanf("%d", &x);
    arr[i] += x;
  }
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(1);
  printf("%d\n", dp[1][m - 1].first + (dp[1][m - 1].second > 0));
}
int main() {
  int tt;
  scanf("%d", &tt);
  while (tt--) {
    solve();
  }
  return 0;
}
