#include <bits/stdc++.h>
using namespace std;
const int maxN = 3100;
const long long INF = 1000000000000000000LL;
int b[maxN];
int w[maxN];
vector<int> g[maxN];
int used[maxN];
void merge(vector<pair<int, long long> >& a, vector<pair<int, long long> >& b) {
  int sza = a.size(), szb = b.size();
  if (a.size() < b.size()) {
  }
  vector<pair<int, long long> > res(sza + szb - 1, make_pair(-1, -1));
  for (int i = 0; i < a.size(); ++i) {
    for (int j = 0; j < b.size(); ++j) {
      if (a[i].first == -1) {
        continue;
      }
      if (a[i].second == -INF && b[j].second == -INF) {
        res[i + j] = max(res[i + j], make_pair(a[i].first + b[j].first, -INF));
      } else if (a[i].second == -INF) {
        if (b[j].second > 0) {
          res[i + j + 1] =
              max(res[i + j + 1], make_pair(a[i].first + b[j].first + 1, -INF));
        } else {
          res[i + j + 1] =
              max(res[i + j + 1], make_pair(a[i].first + b[j].first, -INF));
        }
      } else if (b[j].second == -INF) {
        res[i + j] =
            max(res[i + j], make_pair(a[i].first + b[j].first, a[i].second));
        if (a[i].second > 0) {
          res[i + j + 1] =
              max(res[i + j + 1], make_pair(a[i].first + b[j].first + 1, -INF));
        } else {
          res[i + j + 1] =
              max(res[i + j + 1], make_pair(a[i].first + b[j].first, -INF));
        }
      } else {
        res[i + j] = max(res[i + j], make_pair(a[i].first + b[j].first,
                                               a[i].second + b[j].second));
        if (a[i].second + b[j].second > 0) {
          res[i + j + 1] =
              max(res[i + j + 1], make_pair(a[i].first + b[j].first + 1, -INF));
        }
        if (a[i].second > 0) {
        } else {
        }
        if (b[j].second > 0) {
          res[i + j + 1] =
              max(res[i + j + 1],
                  make_pair(a[i].first + b[j].first + 1, a[i].second));
        } else {
          res[i + j + 1] = max(res[i + j + 1],
                               make_pair(a[i].first + b[j].first, a[i].second));
        }
      }
    }
  }
  a = res;
}
vector<pair<int, long long> > dfsdp(int v) {
  used[v] = 1;
  vector<pair<int, long long> > cur(2, make_pair(-1, -1));
  cur[0] = max(cur[0], make_pair(0, (long long)w[v] - b[v]));
  if (w[v] > b[v]) {
    cur[1] = max(cur[1], make_pair(1, -INF));
  } else {
    cur[1] = max(cur[1], make_pair(0, -INF));
  }
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    if (used[to]) {
      continue;
    }
    auto cres = dfsdp(to);
    merge(cur, cres);
  }
  return cur;
}
void solve() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; ++i) {
    g[i].clear();
    used[i] = 0;
  }
  for (int i = 0; i < n; ++i) {
    cin >> b[i];
  }
  for (int i = 0; i < n; ++i) {
    cin >> w[i];
  }
  for (int i = 1; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    --x, --y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  auto res = dfsdp(0);
  int ans1 = res[m - 1].first;
  if (res[m - 1].first == -INF) {
    ans1 = -1;
  } else {
    if (res[m - 1].second > 0) {
      ++ans1;
    }
  }
  int ans2 = res[m].first;
  if (res[m].second != -INF) {
    ans2 = -1;
  }
  cout << max(ans1, ans2) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  for (int tt = 0; tt < t; ++tt) {
    solve();
  }
  return 0;
}
