#include <bits/stdc++.h>
using namespace std;
int test = 0;
const int MAXN = 200009;
const long long MOD = 119 << 23 | 1;
class {
 public:
  vector<int> V[3333];
  pair<long long, long long> d[3333][3333];
  long long a[3333], sz[3333];
  void solve() {
    int _;
    cin >> _;
    while (_--) {
      int n, m;
      cin >> n >> m;
      for (int i = 1; i <= n; ++i) {
        int u;
        cin >> u;
        a[i] = -u;
      }
      for (int i = 1; i <= n; ++i) {
        int u;
        cin >> u;
        a[i] += u;
      }
      for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        V[u].push_back(v);
        V[v].push_back(u);
      }
      dfs(1, 0);
      cout << d[1][m].first + (d[1][m].second > 0) << '\n';
      for (int i = 1; i <= n; ++i) {
        V[i].clear();
      }
    }
  }
  pair<long long, long long> tmp[3333];
  void dfs(int u, int fa) {
    d[u][1] = {0, a[u]};
    sz[u] = 1;
    for (int v : V[u]) {
      if (v != fa) {
        dfs(v, u);
        for (int i = 0; i <= sz[u] + sz[v]; ++i) tmp[i] = {-1, 0};
        for (int i = 1; i <= sz[u]; ++i) {
          for (int j = 1; j <= sz[v]; ++j) {
            upd1(tmp[i + j], d[u][i], d[v][j]);
            upd2(tmp[i + j - 1], d[u][i], d[v][j]);
          }
        }
        sz[u] += sz[v];
        for (int i = 1; i <= sz[u]; ++i) d[u][i] = tmp[i];
      }
    }
  }
  void upd1(pair<long long, long long> &A, pair<long long, long long> B,
            pair<long long, long long> C) {
    pair<long long, long long> res;
    res.first = C.first + B.first;
    if (C.second > 0) res.first++;
    res.second = B.second;
    if (A.first < res.first)
      A = res;
    else if (A.first == res.first) {
      A.second = max(A.second, res.second);
    }
  }
  void upd2(pair<long long, long long> &A, pair<long long, long long> B,
            pair<long long, long long> C) {
    pair<long long, long long> res;
    res.first = C.first + B.first;
    res.second = C.second + B.second;
    if (A.first < res.first)
      A = res;
    else if (A.first == res.first) {
      A.second = max(A.second, res.second);
    }
  }
} NSPACE;
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}
