#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static unsigned long long splitmix64(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(unsigned long long x) const {
    static const unsigned long long FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
mt19937 random_generator(
    chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 3e3 + 3;
int t;
void read() { cin >> t; }
int n, m, r[maxn];
vector<int> adj[maxn];
vector<pair<int, long long> > dp[maxn];
vector<pair<int, long long> > merge(vector<pair<int, long long> > &a,
                                    vector<pair<int, long long> > &b) {
  vector<pair<int, long long> > ans;
  ans.resize(a.size() + b.size());
  for (auto &i : ans) i = {-(int)1e6, 0};
  for (int i = 0; i < (int)a.size(); i++)
    for (int j = 0; j < (int)b.size(); j++) {
      pair<int, long long> curr1 = {a[i].first + b[j].first, a[i].second};
      pair<int, long long> curr2 = {a[i].first + b[j].first,
                                    a[i].second + b[j].second};
      if (b[j].second > 0) curr1.first++;
      ans[i + j + 1] = max(ans[i + j + 1], curr1);
      ans[i + j] = max(ans[i + j], curr2);
    }
  return ans;
}
void dfs(int ver, int par) {
  dp[ver].clear();
  dp[ver].push_back({0, r[ver]});
  for (auto i : adj[ver])
    if (i != par) {
      dfs(i, ver);
      dp[ver] = merge(dp[ver], dp[i]);
    }
}
void clear() {
  for (int i = 1; i <= n; i++) adj[i].clear();
}
void solve() {
  while (t--) {
    cin >> n >> m;
    clear();
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      r[i] = -a;
    }
    for (int i = 1; i <= n; i++) {
      int a;
      cin >> a;
      r[i] += a;
    }
    for (int i = 1; i <= n - 1; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    dfs(1, -1);
    if (dp[1][m - 1].second > 0) dp[1][m - 1].first++;
    cout << dp[1][m - 1].first << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
