#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
int in() {
  int x;
  cin >> x;
  return x;
}
long long lin() {
  long long x;
  cin >> x;
  return x;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline void print(pair<T, T> p) {
  cout << "(" << p.first << "," << p.second << ") ";
}
template <class T>
inline void print(vector<pair<T, T>> v) {
  for (auto e : v) print(e);
  cout << "\n";
}
template <class T>
inline void print(T v) {
  for (auto e : v) cout << e << " ";
  cout << "\n";
}
void go();
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int Testcases = in();
  while (Testcases--) {
    go();
  }
  return 0;
}
int n, m;
vector<long long> a;
vector<vector<int>> g;
vector<pair<long long, long long>> dfs(int x, int p) {
  vector<pair<long long, long long>> tmp;
  tmp.emplace_back(0, a[x]);
  for (auto e : g[x]) {
    if (e == p) continue;
    vector<pair<long long, long long>> res = dfs(e, x);
    vector<pair<long long, long long>> next(res.size() + tmp.size() - 1,
                                            {-INT_MAX, -INT_MAX});
    for (long long i = 0; i < res.size(); i++) {
      for (long long j = 0; j < tmp.size(); j++) {
        if (chmax(next[i + j].first, res[i].first + tmp[j].first)) {
          next[i + j].second = res[i].second + tmp[j].second;
        } else if (next[i + j].first == res[i].first + tmp[j].first) {
          chmax(next[i + j].second, res[i].second + tmp[j].second);
        }
      }
    }
    tmp = next;
  }
  tmp.emplace_back(tmp.back().first + (tmp.back().second > 0), 0);
  for (long long i = tmp.size() - 1; i >= 1; i--) {
    if (tmp[i - 1].first + (tmp[i - 1].second > 0) > tmp[i].first) {
      tmp[i].first = tmp[i - 1].first + (tmp[i - 1].second > 0);
      tmp[i].second = 0;
    } else if (tmp[i - 1].first + (tmp[i - 1].second > 0) == tmp[i].first) {
      chmax(tmp[i].second, 0ll);
    }
  }
  return tmp;
}
void go() {
  n = in();
  m = in();
  a = vector<long long>(n);
  g = vector<vector<int>>(n);
  for (long long i = 0; i < n; i++) {
    a[i] -= in();
  }
  for (long long i = 0; i < n; i++) a[i] += in();
  for (long long i = 0; i < n - 1; i++) {
    int x = in() - 1, y = in() - 1;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<pair<long long, long long>> ans = dfs(0, -1);
  m--;
  cout << ans[m].first + (ans[m].second > 0) << "\n";
}
