#include <bits/stdc++.h>
using namespace std;
namespace debug {
void __(short x) { cout << x; }
void __(unsigned x) { cout << x; }
void __(int x) { cout << x; }
void __(long long x) { cout << x; }
void __(unsigned long long x) { cout << x; }
void __(double x) { cout << x; }
void __(long double x) { cout << x; }
void __(char x) { cout << x; }
void __(const char* x) { cout << x; }
void __(const string& x) { cout << x; }
void __(bool x) { cout << (x ? "true" : "false"); }
template <class P1, class P2>
void __(const pair<P1, P2>& x) {
  __("("), __(x.first), __(", "), __(x.second), __(")");
}
template <class T>
void __(const vector<T>& x) {
  __("{");
  bool _ffs = 0;
  for (const auto& v : x) __(_ffs ? ", " : ""), __(v), _ffs = 1;
  __("}");
}
template <class T>
void __(const set<T>& x) {
  __("{");
  bool _ffs = 0;
  for (const auto& v : x) __(_ffs ? ", " : ""), __(v), _ffs = 1;
  __("}");
}
template <class T, class T2>
void __(const map<T, T2>& x) {
  __("{");
  bool _ffs = 0;
  for (const auto& v : x)
    __(_ffs ? ", " : ""), __(make_pair(v.first, v.second)), _ffs = 1;
  __("}");
}
void screm() { __("\n"); }
template <class T1, class... T2>
void screm(const T1& t1, const T2&... t2) {
  __(t1);
  if (sizeof...(t2))
    __(" | "), screm(t2...);
  else
    __("\n");
}
void pr() { __("\n"); }
template <class T1, class... T2>
void pr(const T1& t1, const T2&... t2) {
  __(t1);
  if (sizeof...(t2))
    __(" "), pr(t2...);
  else
    __("\n");
}
}  // namespace debug
using namespace debug;
const long long MN = 3005;
const long long inf = 1LL << 60;
long long t, n, m, i, j, d[MN], sz[MN], id[MN], x, y;
vector<long long> adj[MN];
vector<pair<long long, long long> > vec[MN];
void go(long long n, long long p) {
  sz[n] = 1;
  pair<long long, long long> big(-1, -1);
  for (auto v : adj[n]) {
    if (v == p) continue;
    go(v, n);
    if (sz[v] > big.first) big = {sz[v], v};
    sz[n] += sz[v];
  }
  if (big.second == -1)
    id[n] = n;
  else
    id[n] = id[big.second];
  for (auto v : adj[n]) {
    if (v == big.second || v == p) continue;
    long long t = vec[id[v]].size();
    while (t--) vec[id[n]].push_back({0, -inf});
    for (long long i = 0; i < vec[id[v]].size(); i++) {
      for (long long j = vec[id[n]].size() - 1; j >= 0; j--) {
        if (vec[id[v]][i].first + vec[id[n]][j - i].first >
                vec[id[n]][j].first ||
            (vec[id[v]][i].first + vec[id[n]][j - i].first ==
                 vec[id[n]][j].first &&
             vec[id[v]][i].second + vec[id[n]][j - i].second >
                 vec[id[n]][j].second)) {
          vec[id[n]][j] = {vec[id[v]][i].first + vec[id[n]][j - i].first,
                           vec[id[v]][i].second + vec[id[n]][j - i].second};
        }
      }
    }
  }
  if (big.second == -1) vec[id[n]].push_back({0, 0});
  for (long long i = 0; i < vec[id[n]].size(); i++)
    vec[id[n]][i].second += d[n];
  vec[id[n]].push_back({0, -inf});
  for (long long i = 1; i < vec[id[n]].size(); i++) {
    long long s = 0;
    if (vec[id[n]][i - 1].second > 0) s = 1;
    if (vec[id[n]][i - 1].first + s > vec[id[n]][i].first ||
        (vec[id[n]][i - 1].first + s == vec[id[n]][i].first &&
         vec[id[n]][i].second < 0)) {
      vec[id[n]][i] = {vec[id[n]][i - 1].first + s, 0};
    }
  }
}
signed main() {
  scanf("%lld", &t);
  for (long long q = (1); q <= (t); q++) {
    scanf("%lld%lld", &n, &m);
    for (long long i = (1); i <= (n); i++) {
      scanf("%lld", &d[i]);
      adj[i].clear();
      vec[i].clear();
    }
    for (long long i = (1); i <= (n); i++) {
      scanf("%lld", &x);
      d[i] = x - d[i];
    }
    for (long long i = (1); i <= (n - 1); i++) {
      scanf("%lld%lld", &x, &y);
      adj[x].push_back(y);
      adj[y].push_back(x);
    }
    go(1, 0);
    printf("%lld\n", vec[id[1]][m]);
  }
  return 0;
}
