#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const int maxN = 3004;
const long long INF = 1ll << 60;
pair<int, long long> dp[maxN][maxN], temp[maxN];
vector<int> G[maxN];
int T[maxN], sz[maxN];
void updt(pair<int, long long>& a, pair<int, long long>& b) {
  if (a < b) a = b;
}
void dfs(int v, int fat) {
  sz[v] = 1;
  for (int i = (0); i < (int)(maxN); i++) dp[v][i] = temp[i] = {0, -INF};
  dp[v][1] = {0, T[v]};
  for (int u : G[v])
    if (u != fat) {
      dfs(u, v);
      for (int i = (1); i < (int)(sz[v] + 1); i++)
        for (int j = (1); j < (int)(sz[u] + 1); j++) {
          pair<int, long long> prop = {dp[v][i].first + dp[u][j].first,
                                       dp[v][i].second + dp[u][j].second};
          prop.second -= dp[i][j].second;
          updt(temp[i + j], prop);
          prop.second += dp[i][j].second;
          if (dp[i][j].second > 0) prop.first -= 1;
          updt(temp[i + j - 1], prop);
        }
      sz[v] += sz[u];
      copy(temp, temp + sz[v] + 1, dp[v]);
    }
  for (int i = (1); i < (int)(sz[v] + 1); i++)
    if (dp[v][i].second > 0) dp[v][i].first++;
}
void solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = (1); i < (int)(n + 1); i++) scanf("%d", T + i);
  for (int i = (1); i < (int)(n + 1); i++) {
    int a;
    scanf("%d", &a);
    T[i] = a - T[i];
  }
  for (int i = (1); i < (int)(n); i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(1, 0);
  printf("%d\n", dp[1][m].first);
  for (int i = (1); i < (int)(n + 1); i++) G[i].resize(0);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) solve();
  return 0;
}
