#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static unsigned long long splitmix64(unsigned long long x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(unsigned long long x) const {
    static const unsigned long long FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
mt19937 random_generator(
    chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 3e3 + 3;
int t;
void read() { cin >> t; }
int n, m;
long long r[maxn];
vector<int> adj[maxn];
pair<int, long long> dp[maxn][maxn];
pair<int, long long> nxt[maxn];
void dfs(int ver, int par) {
  for (auto i : adj[ver])
    if (i != par) dfs(i, ver);
  for (int i = 0; i <= m; i++) dp[ver][i] = {-(int)1e6, -(long long)1e12};
  dp[ver][1] = {0, r[ver]};
  if (r[ver] > 0) dp[ver][1].first++;
  for (auto i : adj[ver])
    if (i != par) {
      for (int j = 1; j <= m; j++) {
        nxt[j] = {-(int)1e9, -(long long)1e15};
        for (int k = 1; k <= j; k++) {
          pair<int, long long> curr1 = {dp[i][k].first + dp[ver][j - k].first,
                                        dp[ver][j - k].second};
          pair<int, long long> curr2 = {
              dp[i][k].first + dp[ver][j - k + 1].first,
              dp[ver][j - k + 1].second + dp[i][k].second};
          if (dp[ver][j - k + 1].second > 0) curr2.first--;
          if (dp[i][k].second > 0) curr2.first--;
          if (curr2.second > 0) curr2.first++;
          nxt[j] = max({nxt[j], curr1, curr2});
        }
      }
      for (int j = 1; j <= m; j++) dp[ver][j] = nxt[j];
    }
}
void clear() {
  for (int i = 1; i <= n; i++) adj[i].clear();
}
void solve() {
  while (t--) {
    cin >> n >> m;
    clear();
    for (int i = 1; i <= n; i++) {
      long long a;
      cin >> a;
      r[i] = -a;
    }
    for (int i = 1; i <= n; i++) {
      long long a;
      cin >> a;
      r[i] += a;
    }
    for (int i = 1; i <= n - 1; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    dfs(1, -1);
    cout << dp[1][m].first << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  read();
  solve();
}
