#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
constexpr int DEBUG = 0;
struct Edge {
  const int from, to;
  Edge(int from, int to) : from(from), to(to) {}
};
vector<vector<Edge>> ReadUndirectedGraph(int n, int m,
                                         bool is_one_indexed = false) {
  vector<vector<Edge>> graph(n);
  for (int i = 0; i < m; i++) {
    int v1, v2;
    cin >> v1 >> v2;
    if (is_one_indexed) {
      v1--;
      v2--;
    }
    graph[v1].push_back(Edge(v1, v2));
    graph[v2].push_back(Edge(v2, v1));
  }
  return graph;
}
template <class T>
inline bool UpdateMax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
void SolveCase() {
  int n, m;
  cin >> n >> m;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    int64 x;
    cin >> x;
    xs[i] -= x;
  }
  for (int i = 0; i < n; i++) {
    int64 x;
    cin >> x;
    xs[i] += x;
  }
  auto graph = ReadUndirectedGraph(n, n - 1, true);
  vector<vector<pair<int, int64>>> dp(n);
  auto merge_fn = [](const vector<pair<int, int64>>& as,
                     const vector<pair<int, int64>>& bs) {
    vector<pair<int, int64>> cs(as.size() + bs.size(), {-1, 0});
    for (int k1 = 0; k1 < as.size(); k1++) {
      for (int k2 = 0; k2 < bs.size(); k2++) {
        UpdateMax(
            cs[k1 + k2 + 1],
            {as[k1].first + bs[k2].first + (bs[k2].second > 0), as[k1].second});
        UpdateMax(cs[k1 + k2],
                  {as[k1].first + bs[k2].first, as[k1].second + bs[k2].second});
      }
    }
    return cs;
  };
  function<void(int, int)> dfs_fn = [&](int v, int p) {
    vector<pair<int, int64>> tuples = {make_pair(0, xs[v])};
    for (const auto& e : graph[v]) {
      if (e.to == p) continue;
      dfs_fn(e.to, v);
      tuples = merge_fn(tuples, dp[e.to]);
    }
    dp[v] = tuples;
  };
  dfs_fn(0, -1);
  int ans = dp[0][m - 1].first + (dp[0][m - 1].second > 0);
  cout << ans << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int num_cases;
  cin >> num_cases;
  for (int i = 0; i < num_cases; i++) SolveCase();
}
