#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
using ll = long long;
const ll intinf = 1e9;
const ll inf = 1e18;
const int maxn = 3333;
int n, m;
vector<int> g[maxn];
ll b[maxn], w[maxn];
void setmax(pair<int, ll> &x, pair<int, ll> y) { x = max(x, y); }
void merge(vector<vector<pair<int, ll>>> &dpat,
           vector<vector<pair<int, ll>>> dpto) {
  int n = dpat.size();
  int m = dpto.size();
  vector<vector<pair<int, ll>>> dp(
      n + m + 1, vector<pair<int, ll>>(2, make_pair(-intinf, -inf)));
  for (int i = 1; i < n; i++) {
    for (int s1 = 0; s1 <= 1; s1++) {
      for (int j = 1; j < m; j++) {
        for (int s2 = 0; s2 <= 1; s2++) {
          if (s1 == 0 && s2 == 0) {
            setmax(dp[i + j + 1][true],
                   {dpat[i][s1].first + dpto[j][s2].first, 0});
            setmax(dp[i + j][false],
                   {dpat[i][s1].first + dpto[j][s2].first, 0});
          } else if (s1 == 1 && s2 == 1) {
            setmax(dp[i + j - 1][true],
                   {dpat[i][s1].first + dpto[j][s2].first,
                    dpat[i][s1].second + dpto[j][s2].second});
            setmax(dp[i + j - 1][false],
                   {dpat[i][s1].first + dpto[j][s2].first +
                        ((dpat[i][s1].second + dpto[j][s2].second) > 0),
                    0});
          } else if (s1 == 0 && s2 == 1) {
            setmax(dp[i + j][false],
                   {dpat[i][s1].first + dpto[j][s2].first +
                        ((dpat[i][s1].second + dpto[j][s2].second) > 0),
                    0});
          } else if (s1 == 1 && s2 == 0) {
            setmax(dp[i + j][true], {dpat[i][s1].first + dpto[j][s2].first,
                                     dpat[i][s1].second + dpto[j][s2].second});
            setmax(dp[i + j][false],
                   {dpat[i][s1].first + dpto[j][s2].first +
                        ((dpat[i][s1].second + dpto[j][s2].second) > 0),
                    0});
          } else {
            assert(false);
          }
        }
      }
    }
  }
  swap(dpat, dp);
}
vector<vector<pair<int, ll>>> dp[maxn];
void dfs(int at, int p) {
  dp[at].resize(2, vector<pair<int, ll>>(2));
  bool isleaf = true;
  for (int to : g[at]) {
    if (to == p) continue;
    isleaf = false;
  }
  dp[at][0][true] = dp[at][0][false] = {0, -inf};
  dp[at][1][true] = {0, w[at] - b[at]};
  if (isleaf) {
    dp[at][1][false] = {(w[at] - b[at]) > 0, 0};
  }
  for (int to : g[at]) {
    if (to == p) continue;
    dfs(to, at);
    merge(dp[at], dp[to]);
  }
}
int solve() {
  cin >> n >> m;
  for (int i = 0; i <= n; i++) {
    b[i] = w[i] = 0;
    g[i].clear();
    dp[i].clear();
  }
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= n; i++) {
    cin >> w[i];
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, 0);
  int res = dp[1][m][false].first;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    cout << solve() << "\n";
  }
  return 0;
}
