#include <bits/stdc++.h>
using namespace std;
const long long ool = 1e15 + 9;
const int oo = 1e7 + 9, base = 1e9 + 7;
const double eps = 1e-7;
const int N = 4e3 + 6;
int n, m;
long long a[N], b[N];
vector<int> g[N];
vector<pair<int, long long> > d[N];
void dfs(int v, int par) {
  g[v].erase(remove(g[v].begin(), g[v].end(), par), g[v].end());
  d[v].emplace_back(0, b[v] - a[v]);
  for (auto to : g[v]) {
    dfs(to, v);
  }
  for (auto to : g[v]) {
    vector<pair<int, long long> > dp((int)d[v].size() + (int)d[to].size(),
                                     {-1, 0});
    for (int i = 0; i <= (int)d[v].size() - 1; ++i) {
      for (int j = 0; j <= (int)d[to].size() - 1; ++j) {
        dp[i + j] = max(dp[i + j], {d[v][i].first + d[to][j].first,
                                    d[v][i].second + d[to][j].second});
        dp[i + j + 1] = max(dp[i + j + 1], {d[v][i].first + d[to][j].first +
                                                (d[to][j].second > 0),
                                            d[v][i].second});
      }
    }
    d[v] = dp;
  }
}
int main() {
  ios_base ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    for (int i = 1; i <= n; ++i) {
      cin >> a[i];
    }
    for (int i = 1; i <= n; ++i) {
      cin >> b[i];
    }
    for (int i = 1; i <= n - 1; ++i) {
      int x, y;
      cin >> x >> y;
      g[x].emplace_back(y);
      g[y].emplace_back(x);
    }
    dfs(1, 0);
    cout << d[1][m - 1].first + (d[1][m - 1].second > 0) << "\n";
    for (int i = 1; i <= n; ++i) {
      g[i].clear();
      d[i].clear();
    }
  }
  return 0;
}
