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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;
        vector<int> b(n), w(n), c(n);
        for (auto& x : b) cin >> x;
        for (auto& x : w) cin >> x;
        for (int i = 0; i < n; ++i) c[i] = w[i] - b[i];
        vector<vector<int>> G(n);
        for (int i = 0; i < n - 1; ++i) {
            int x, y;
            cin >> x >> y;
            --x, --y;
            G[x].push_back(y);
            G[y].push_back(x);
        }
        vector<int> sz(n, 1);
        vector<vector<pair<int, ll>>> dp(n);
        auto dfs = [&](auto& dfs, int v, int p) -> void {
            dp[v] = {{0, c[v]}};
            for (int c : G[v]) {
                if (c == p) continue;
                dfs(dfs, c, v);
                vector<pair<int, ll>> tmp(sz[v] + sz[c]);
                for (int i = 0; i < sz[v]; ++i) {
                    for (int j = 0; j <= sz[c]; ++j) {
                        tmp[i + j] = max(tmp[i + j], {dp[v][i].first + dp[c][j].first, dp[v][i].second + dp[c][j].second});
                    }
                }
                sz[v] += sz[c];
                dp[v] = tmp;
            }
            dp[v].push_back({0, 0});
            for (int i = sz[v]; i > 0; --i) {
                dp[v][i] = max(dp[v][i], {dp[v][i - 1].first + (dp[v][i - 1].second > 0), 0});
            }
        };
        dfs(dfs, 0, -1);
        cout << dp[0][m - 1].first + (dp[0][m - 1].second > 0) << "\n";
    }
}