#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;
int sz[N];
long long a[N], b[N];
vector<int> g[N];
pair<int, long long> d[N][N];
void dfs(int v, int par) {
  g[v].erase(remove(g[v].begin(), g[v].end(), par), g[v].end());
  sz[v] = 1;
  for (auto to : g[v]) {
    dfs(to, v);
    sz[v] += sz[to];
  }
  for (int i = 0; i <= sz[v]; ++i) d[v][i] = {0, 0};
  d[v][1] = {(b[v] - a[v] > 0), b[v] - a[v]};
  for (auto to : g[v]) {
    for (int j = sz[v]; j >= 1; --j) {
      pair<int, long long> val = {0, 0};
      for (int k = 0; k <= min(sz[to], j - 1); ++k) {
        if (k)
          val = max(val,
                    {d[v][j - k].first + d[to][k].first, d[v][j - k].second});
        int good_diff = -(d[v][j - k].second > 0) - (d[to][k + 1].second > 0) +
                        (d[v][j - k].second + d[to][k + 1].second > 0);
        val = max(val, {d[v][j - k].first + d[to][k + 1].first + good_diff,
                        d[v][j - k].second + d[to][k + 1].second});
      }
      d[v][j] = val;
    }
  }
}
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].first << "\n";
    for (int i = 1; i <= n; ++i) g[i].clear();
  }
  return 0;
}
