#include <bits/stdc++.h>
using namespace std;
vector<long long> delta;
vector<vector<int> > data;
pair<int, long long> dp[2007][2007];
pair<int, long long> dp2[2007];
int dfs(int vertex, int last) {
  for (int i = 0; i < 2007; ++i) {
    dp[vertex][i] = {-1e9, -1e18}, dp2[i] = {-1e9, -1e18};
  }
  dp[vertex][1] = {(delta[vertex] > 0), delta[vertex]};
  int sz = 1;
  for (int i = 0; i < data[vertex].size(); ++i) {
    int to = data[vertex][i];
    if (to == last) continue;
    int tam = dfs(to, vertex);
    for (int e = 0; e <= tam + sz; ++e) dp2[e] = {-1e9, -1e18};
    for (int j = 0; j <= sz; ++j)
      for (int k = 0; k <= tam; ++k) {
        pair<int, long long> p = {dp[vertex][j].first + dp[to][k].first,
                                  dp[vertex][j].second};
        if (p > dp2[j + k]) dp2[j + k] = p;
        if (j + k > 0) {
          p = {dp[vertex][j].first + dp[to][k].first,
               dp[vertex][j].second + dp[to][k].second};
          if (dp[vertex][j].second > 0) p.first--;
          if (dp[to][k].second > 0) p.first--;
          if (dp[vertex][j].second + dp[to][k].second > 0) p.first++;
          if (p > dp2[j + k - 1]) dp2[j + k - 1] = p;
        }
      }
    for (int e = 0; e <= tam + sz; ++e) dp[vertex][e] = dp2[e];
    sz += tam;
  }
  return sz;
}
void solve() {
  int n, m;
  cin >> n >> m;
  delta.assign(n, 0);
  for (int i = 0; i < n; ++i) {
    long long first;
    cin >> first;
    delta[i] -= first;
  }
  for (int i = 0; i < n; ++i) {
    long long first;
    cin >> first;
    delta[i] += first;
  }
  data.assign(n, {});
  for (int i = 0; i < n - 1; ++i) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    data[u].push_back(v), data[v].push_back(u);
  }
  dfs(0, -1);
  cout << dp[0][m].first << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) solve();
}
