#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N = 3030;
const int inf = 1e9;

int n, m;
pair<int, int> dp[N][N];
int w[N], sz[N];
vector<int> adj[N];

void dfs(int v, int par = -1) {
  dp[v][1] = {w[v] > 0, w[v]};
  sz[v] = 1;
  for (int u : adj[v]) {
    if (u == par) {
      continue;
    }
    dfs(u, v);
    vector<pair<int, int>> nxt(sz[v] + sz[u] + 1, make_pair(-1, -1));
    for (int i = sz[v]; i >= 1; i--) {
      for (int j = sz[u]; j >= 1; j--) {
        nxt[i + j] = max(nxt[i + j], {dp[v][i].first + dp[u][j].first, dp[v][i].second});
        int x = dp[v][i].first + dp[u][j].first;
        int y = dp[v][i].second + dp[u][j].second;
        if (y <= 0 && dp[v][i].second > 0) {
          x--;
        }
        if (y <= 0 && dp[u][j].second > 0) {
          x--;
        }
        //cout << v << ' ' << u << ' ' << i << ' ' << j << ' ' << x << ' ' << y << endl;
        nxt[i + j - 1] = max(nxt[i + j - 1], {x, y});
      }
    }
    for (int i = 0; i < sz[v] + sz[u] + 1; i++) {
      dp[v][i] = nxt[i];
    }
    sz[v] += sz[u];
  }
}

main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int tot_cas;
  cin >> tot_cas;
  for (int cas = 1; cas <= tot_cas; cas++) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      adj[i].clear();
      for (int j = 1; j <= m; j++) {
        dp[i][j] = {-inf, -inf};
      }
    }
    for (int i = 0; i < n; i++) {
      cin >> w[i];
    }
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      w[i] = x - w[i];
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    dfs(0);
    cout << dp[0][m].first << endl;
  }
  return 0;
}
