#include <bits/stdc++.h>
using namespace std;
const int maxn = 3005;
struct node {
  long long r, l;
  node(long long r, long long l) : r(r), l(l) {}
  node() : r(), l() {}
  bool operator<(const node& o) const {
    if (r == o.r) {
      if (l <= 0 && o.l <= 0)
        return l < o.l;
      else if (l > 0 && o.l > 0)
        return l < o.l;
      else
        return l > o.l;
    } else
      return r < o.r;
  }
  node operator+(const node& o) const { return node(r + o.r, l + o.l); }
} dp[maxn][maxn], g[maxn];
vector<int> E[maxn];
long long siz[maxn], w[maxn], b[maxn];
int n, m;
void dfs(int x, int fa) {
  dp[x][1] = node(0, w[x] - b[x]);
  if (dp[x][1].l > 0) dp[x][1].r++;
  siz[x] = 1;
  for (auto i : E[x]) {
    if (i == fa) continue;
    dfs(i, x);
    for (int j = 1; j <= siz[x] + siz[i]; j++) g[j] = node(-1, 0);
    for (int j = 1; j <= siz[x]; j++) {
      for (int k = 1; k <= siz[i]; k++) {
        node t1, t2;
        t1 = t2 = dp[i][k];
        if (dp[x][j].l > 0 && t1.l > 0) t1.r--;
        if (dp[x][j].l + t1.l <= 0 && (dp[x][j].l > 0 || t1.l > 0)) t1.r--;
        t2.l = 0;
        g[j + k - 1] = max(g[j + k - 1], dp[x][j] + t1);
        g[j + k] = max(g[j + k], dp[x][j] + t2);
      }
    }
    siz[x] += siz[i];
    for (int j = 1; j <= siz[x]; j++) dp[x][j] = g[j];
  }
}
void getdata() {
  cout << n << " " << m << endl;
  for (int i = 1; i <= n; i++) cout << w[i] << " ";
  cout << endl;
  for (int i = 1; i <= n; i++) {
    for (auto j : E[i])
      if (j > i) cout << i << " " << j << endl;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T, tt;
  cin >> T;
  tt = T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      E[i].clear();
      for (int j = 1; j <= n; j++) dp[i][j] = node(-1, 0);
    }
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) cin >> w[i];
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      E[x].push_back(y);
      E[y].push_back(x);
    }
    dfs(1, 0);
    cout << dp[1][m].r << '\n';
  }
}
