#include <bits/stdc++.h>
using namespace std;
const int N = 3010;
const int INF = 0x3f3f3f3f;
int h[N], e[2 * N], ne[2 * N], idx;
pair<int, int> arr[N];
int sz[N];
pair<int, int> f[N][N];
pair<int, int> g[N];
int n, m;
pair<int, int> max(pair<int, int> a, pair<int, int> b) { return a > b ? a : b; }
pair<int, int> operator+(pair<int, int> a, pair<int, int> b) {
  return pair<int, int>(a.first + b.first, a.second + b.second);
}
void add(int a, int b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; }
pair<int, int> work(pair<int, int> x) {
  x.first += x.second > 0;
  x.second = 0;
  return x;
}
int dfs(int u, int fa) {
  sz[u] = 0;
  for (int i = 0; i <= m; i++) f[u][i] = {-INF, 0};
  f[u][0] = {0, 0};
  for (int i = h[u]; i != -1; i = ne[i]) {
    int j = e[i];
    if (j == fa) continue;
    dfs(j, u);
    for (int k = 0; k <= m; k++) g[k] = {-INF, 0};
    for (int k = 0; k <= sz[u] && k <= m; k++) {
      for (int h = 0; h <= (sz[u] + sz[j]) && h <= m; h++) {
        g[k + h] = max(g[k + h], f[u][k] + f[j][h]);
        if (h < m) g[k + h + 1] = max(g[k + h + 1], f[u][k] + work(f[j][h]));
      }
    }
    for (int k = 0; k <= m && k <= (sz[u] + sz[j]); k++) {
      f[u][k] = g[k];
    }
    sz[u] += sz[j];
  }
  ++sz[u];
  for (int i = 0; i <= m; i++) {
    f[u][i].second += (arr[u].first - arr[u].second);
  }
  return sz[u];
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    cin >> n >> m;
    memset(h, -1, sizeof h);
    for (int i = 1; i <= n; i++) {
      cin >> arr[i].first;
    }
    for (int i = 1; i <= n; i++) {
      cin >> arr[i].second;
    }
    for (int i = 1; i < n; i++) {
      int a, b;
      cin >> a >> b;
      add(a, b);
      add(b, a);
    }
    dfs(1, -1);
    f[1][m - 1] = work(f[1][m - 1]);
    cout << f[1][m - 1].first << endl;
  }
}
