#include <bits/stdc++.h>
using i64 = long long;
struct node {
  int ans;
  i64 adv;
  node(int ans = -1, i64 adv = 0) : ans(ans), adv(adv) {}
  node operator+(const node b) const { return node(ans + b.ans, adv + b.adv); }
  node operator+() const { return node(ans + (adv > 0)); }
  bool operator<(const node b) const {
    if (ans == b.ans) {
      return adv < b.adv;
    }
    return ans < b.ans;
  }
};
std::vector<node> merge(std::vector<node> &a, std::vector<node> &b) {
  std::vector<node> res(a.size() + b.size());
  for (int i = 0; i < int(a.size()); i++) {
    for (int j = 0; j < int(b.size()); j++) {
      res[i + j] = std::max(res[i + j], a[i] + b[j]);
      res[i + j + 1] = std::max(res[i + j + 1], a[i] + +b[j]);
    }
  }
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int t;
  std::cin >> t;
  while (t--) {
    int n, m;
    std::cin >> n >> m;
    std::vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
      std::cin >> a[i];
    }
    for (int i = 0; i < n; i++) {
      std::cin >> b[i];
    }
    std::vector<std::vector<int>> e(n);
    for (int i = 0; i < n - 1; i++) {
      int u, v;
      std::cin >> u >> v;
      u--;
      v--;
      e[u].push_back(v);
      e[v].push_back(u);
    }
    std::vector<std::vector<node>> dp(n, std::vector<node>(1, node(0)));
    std::function<void(int, int)> dfs = [&](int u, int p) {
      dp[u][0] = node(0, -a[u] + b[u]);
      for (auto v : e[u]) {
        if (v != p) {
          dfs(v, u);
          dp[u] = merge(dp[u], dp[v]);
        }
      }
    };
    dfs(0, -1);
    assert(dp[0].size() == n);
    std::cout << (+dp[0][m - 1]).ans << "\n";
  }
  return 0;
}
