#include <bits/stdc++.h>
using namespace std;
const int nax = 3333;
const long long oo = 1e18;
int b[nax], c[nax];
int n, m;
vector<int> g[nax];
pair<long long, long long> dp[nax][nax], nxt[nax];
void calc(int u, int p) {
  dp[u][0].first = c[u];
  for (int v : g[u]) {
    if (v == p) continue;
    calc(v, u);
    for (int j = 0; j <= m; j++) {
      nxt[j] = {-oo, 0};
    }
    for (int x = 0; x <= m; x++) {
      for (int y = 0; y <= m; y++) {
        if (dp[u][x].first == -oo || dp[v][y].first == -oo) break;
        if (x + y > m) break;
        pair<long long, long long> nxx;
        nxx.first = dp[u][x].first + dp[v][y].first;
        nxx.second = dp[u][x].second + dp[v][y].second;
        if (nxx.second > nxt[x + y].second) {
          nxt[x + y] = nxx;
        } else if (nxx.second == nxt[x + y].second &&
                   nxx.first > nxt[x + y].first) {
          nxt[x + y] = nxx;
        }
        if (x + y + 1 > m) continue;
        nxx.first = dp[u][x].first;
        nxx.second = dp[v][y].first > 0;
        nxx.second += dp[u][x].second + dp[v][y].second;
        if (nxx.second > nxt[x + y + 1].second) {
          nxt[x + y + 1] = nxx;
        } else if (nxx.second == nxt[x + y + 1].second &&
                   nxx.first > nxt[x + y + 1].first) {
          nxt[x + y + 1] = nxx;
        }
      }
    }
    for (int j = 0; j <= m; j++) {
      dp[u][j] = nxt[j];
    }
  }
}
void solve() {
  cin >> n >> m;
  m--;
  for (int i = 1; i <= n; i++) cin >> b[i];
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    c[i] = x - b[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= m; j++) dp[i][j] = {-oo, 0};
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  calc(1, 0);
  cout << (dp[1][m].first > 0) + dp[1][m].second << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
