#include <bits/stdc++.h>
using namespace std;
int t;
int n, m, u, v;
long long b, w;
struct Village {
  int win;
  long long adv;
  Village(int w = -1, long long a = 0) : win(w), adv(a) {}
  Village operator+(const Village &b) const {
    return Village(win + b.win, adv + b.adv);
  }
  Village operator+() const { return Village(win + (adv > 0)); }
  bool operator<(const Village &b) const {
    return win < b.win || (win == b.win && adv < b.adv);
  }
};
vector<vector<Village> > f;
vector<vector<int> > ga;
vector<Village> add(vector<Village> &a, vector<Village> &b) {
  vector<Village> c(a.size() + b.size());
  for (int i = 0; i < a.size(); i++) {
    for (int j = 0; j < b.size(); j++) {
      c[i + j] = max(c[i + j], a[i] + b[j]);
      c[i + j + 1] = max(c[i + j + 1], a[i] + +b[j]);
    }
  }
  return c;
}
void tree(int x, int p) {
  for (int i = 0; i < ga[x].size(); i++) {
    int y = ga[x][i];
    if (y == p) continue;
    tree(y, x);
    f[x] = add(f[x], f[y]);
  }
}
void functio() {
  cin >> n >> m;
  f = vector<vector<Village> >(n, vector<Village>(1, Village(0)));
  for (int i = 0; i < n; i++) {
    cin >> b;
    f[i][0].adv -= b;
  }
  for (int i = 0; i < n; i++) {
    cin >> w;
    f[i][0].adv += w;
  }
  ga = vector<vector<int> >(n);
  for (int i = 1; i < n; i++) {
    cin >> u >> v;
    u--;
    v--;
    ga[u].push_back(v);
    ga[v].push_back(u);
  }
  tree(0, -1);
  cout << (+f[0][m - 1]).win << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> t;
  while (t--) functio();
  return 0;
}
