#include <bits/stdc++.h>
using namespace std;
struct Group {
  int win;
  long long int adv;
  Group(int win = -1, long long int adv = 0) : win(win), adv(adv) {}
  Group operator+(const Group& o) const {
    return Group(win + o.win, adv + o.adv);
  }
  Group operator+() const { return Group(win + (adv > 0)); }
  bool operator<(const Group& o) const {
    return win < o.win || win == o.win && adv < o.adv;
  }
};
vector<vector<Group> > dp;
vector<vector<int> > adj;
vector<Group> dp_solve(const vector<Group>& fa, const vector<Group>& fb) {
  vector<Group> _new(fa.size() + fb.size());
  for (int a = 0; a < fa.size(); ++a) {
    for (int b = 0; b < fb.size(); ++b) {
      _new[a + b] = max(_new[a + b], fa[a] + fb[b]);
      _new[a + b + 1] = max(_new[a + b + 1], fa[a] + +fb[b]);
    }
  }
  return _new;
}
void dfs(int u, int fa) {
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    if (fa == v) continue;
    dfs(v, u);
    dp[u] = dp_solve(dp[u], dp[v]);
  }
}
int solve() {
  int n, m;
  scanf("%d%d", &n, &m);
  dp = vector<vector<Group> >(n, vector<Group>(1, Group(0)));
  adj = vector<vector<int> >(n);
  for (int i = 0; i < n; ++i) {
    int b;
    scanf("%d", &b);
    dp[i][0].adv -= b;
  }
  for (int i = 0; i < n; ++i) {
    int w;
    scanf("%d", &w);
    dp[i][0].adv += w;
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  dfs(0, -1);
  return (+dp[0][m - 1]).win;
}
int main() {
  int z;
  for (scanf("%d", &z); z--; printf("%d\n", solve()))
    ;
}
