#include <bits/stdc++.h>
using namespace std;
vector<long long> w, b;
vector<vector<int> > g;
class stav {
 public:
  int win;
  long long adv;
};
vector<vector<stav> > dp;
stav better(stav a, stav b) {
  if (a.win == b.win) {
    return (a.adv > b.adv ? a : b);
  }
  return (a.win > b.win ? a : b);
}
vector<int> s;
int dfs(int vr, int p) {
  s[vr] = 1;
  for (int i : g[vr]) {
    if (i != p) {
      s[vr] += dfs(i, vr);
    }
  }
  dp[vr][0] = {0, w[vr] - b[vr]};
  for (int i : g[vr]) {
    if (i != p) {
      vector<stav> nw(dp[vr].size() + dp[i].size(), {-1, 0});
      for (int j = 0; j < dp[vr].size(); j++) {
        if (dp[vr][j].win != -1) {
          for (int k = 0; k < dp[i].size(); k++) {
            if (dp[i][k].win != -1) {
              nw[j + k] = better(nw[j + k], {dp[vr][j].win + dp[i][k].win,
                                             dp[vr][j].adv + dp[i][k].adv});
              nw[j + k + 1] = better(
                  nw[j + k + 1],
                  {dp[vr][j].win + dp[i][k].win + (dp[i][k].adv > 0 ? 1 : 0),
                   dp[vr][j].adv});
            }
          }
        }
      }
      dp[vr] = nw;
    }
  }
  return s[vr];
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    b.clear();
    w.clear();
    g.clear();
    s.clear();
    dp.clear();
    int n, m;
    cin >> n >> m;
    b.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> b[i];
    }
    w.resize(n);
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    g.resize(n);
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      g[a].push_back(b);
      g[b].push_back(a);
    }
    dp.resize(n, vector<stav>(1, {-1, 0}));
    s.resize(n);
    dfs(0, -1);
    int ans = (dp[0][m - 1].adv > 0 ? 1 : 0) + dp[0][m - 1].win;
    cout << ans << "\n";
  }
  return 0;
}
