#include <bits/stdc++.h>
using namespace std;
const long long N = 3e3 + 2;
const long long inf = 1e15 + 7;
vector<long long> adj[N];
long long pts[N], sz[N];
pair<long long, long long> dp[2][N][N];
void dfs(long long x, long long p) {
  dp[0][x][0] = {0, pts[x]};
  sz[x] = 1;
  for (long long i : adj[x]) {
    if (i != p) {
      dfs(i, x);
      for (long long l = sz[x] + sz[i] - 1; l >= 0; l--) {
        for (long long k = 0; k <= sz[i]; k++) {
          long long j = l - k;
          if (j > sz[x] || j < 0) {
            continue;
          }
          dp[0][x][j + k] = max(pair<long long, long long>(
                                    dp[0][x][j].first + dp[1][i][k].first,
                                    dp[0][x][j].second + dp[1][i][k].second),
                                pair<long long, long long>(
                                    dp[0][x][j].first + dp[0][i][k].first,
                                    dp[0][x][j].second + dp[0][i][k].second));
        }
      }
      sz[x] += sz[i];
    }
  }
  for (long long i = 1; i <= sz[x]; i++) {
    if (dp[0][x][i - 1].second > 0) {
      dp[1][x][i] = {dp[0][x][i - 1].first + 1, 0};
    } else {
      dp[1][x][i] = {dp[0][x][i - 1].first, 0};
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long t, n, m, i, j, k, l;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (i = 1; i <= n; i++) {
      cin >> j;
      pts[i] = -j;
    }
    for (i = 1; i <= n; i++) {
      cin >> j;
      pts[i] += j;
    }
    for (i = 1; i < n; i++) {
      cin >> j >> k;
      adj[j].push_back(k);
      adj[k].push_back(j);
    }
    for (i = 1; i <= n; i++) {
      for (j = 0; j <= n; j++) {
        dp[0][i][j] = dp[1][i][j] = {-inf, -inf};
      }
    }
    dfs(1, 1);
    cout << dp[1][1][m].first << '\n';
    assert(dp[1][1][m].second == 0);
    for (i = 1; i <= n; i++) {
      adj[i].clear();
    }
  }
}
