//1280 D

#include <bits/stdc++.h>

using namespace std;

typedef int int2;
#define int long long
#define pi pair<int, int>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define f first
#define s second
const int inf = 1e18;

int t;

void print(pi p) {
    cout << "( " << p.f << ", " << p.s << ") ";
}

void printdp(int idx, auto &dp, auto &sub, auto &adj) {
        cout << "printing dp[" << idx << "]:\n";
        for (int i = 0; i <= (int)adj[idx].size(); i++) {
            for (int j = 1; j <= sub[idx]; j++) {
                print(dp[idx][i][j]);
            }
            cout << "\n";
        }
        cout << "\n";
}

int2 main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    // freopen("D.out", "w", stdout);
    cin >> t;
    while (t--) {
        int n, m;
        cin >> n >> m;

        vector<int> b(n + 1), w(n + 1);

        for (int i = 1; i <= n; i++) {
            cin >> b[i];
        }
        for (int i = 1; i <= n; i++) {
            cin >> w[i];
        }

        vector<vector<int>> adj(n + 1);
        for (int i = 1; i < n; i++) {
            int u, v;
            cin >> u >> v;
            adj[u].pb(v);
            adj[v].pb(u);
        }

        vector<int> ps(n + 1);
        vector<int> sub(n + 1);
        fill(ps.begin(), ps.end(), -1);

        function<void(int, int)> dfs0 = [&](int u, int p) {
            sub[u] = 1;
            for (int v: adj[u]) {
                if (v == p) {ps[u] = p; /*cout << "u: " << u  <<", p: " << p << "\n";*/}
                else {
                    dfs0(v, u);
                    sub[u] += sub[v];
                }
            }
        };

        dfs0(1, 1);


        for (int i = 1; i <= n; i++) {
            vector<int> &edges = adj[i];
            if (~ps[i]) {
                edges.erase(remove_if(edges.begin(), edges.end(), [&](auto u){return u == ps[i];}), edges.end());
            }
        }

        vector<vector<vector<pi>>> dp(n + 1);
        vector<vector<pi>> dp2(n + 1);

        for (int i = 1; i <= n; i++) {
            dp[i].resize((int)adj[i].size() + 1);
        }


        function<void(int, int)> dfs1 = [&](int u, int p) {
            vector<int> &children = adj[u];
            // cout << "u: " << u << "\n";
            dp[u][0].resize(sub[u] + 1);
            fill(dp[u][0].begin(), dp[u][0].end(), mp(-1, -1));
            dp[u][0].resize(sub[u] + 1, mp(-1, -1));
            if (w[u] > b[u]) {
                dp[u][0][1] = {1, w[u] - b[u]};
            } else {
                dp[u][0][1] = {0, w[u] - b[u]};
            }
            int num_children = children.size();
            // cout << "num_children: " << num_children << "\n";
            for (int i = 1; i <= num_children; i++) {
                // cout << "u: " << u << ", i: " << i << "\n";
                int v = children[i - 1];
                dfs1(v, u);
                dp[u][i].resize(sub[u] + 1, mp(-1, -1));
                // pull dp val from dp2[v][.]
                for (int j = 1; j <= sub[u]; j++) {
                    // compute dp[u][i][j]
                    // if (u == 2 and i == 1 and j == 1) {
                    //     cout << "u: " << u << ", i: " << i << ", j: " << j << "\n";
                    //     // requires dp[2][0][1] and dp2[3][1]
                    // }
                    for (int k = 1; k <= min(sub[v], j); k++) {
                        pi d1 = dp2[v][k];
                        pi d2 = dp[u][i - 1][j - k]; //don't merge
                        pi d3 = dp[u][i - 1][j - k + 1]; // merge
                        // try with d2
                        if (~d2.f) {
                            dp[u][i][j] = max(dp[u][i][k], mp(d1.f + d2.f, d1.s));
                        }
                        
                        // try with d3
                        if (~d3.f) {
                            if (d1.s + d3.s > 0) {
                                // merge
                                if (min(d1.s, d3.s) <= 0) dp[u][i][j] = max(dp[u][i][j], mp(d1.f + d3.f, d1.s + d3.s));
                                else dp[u][i][j] = max(dp[u][i][j], mp(d1.f + d3.f - 1, d1.s + d3.s));
                            } else if (max(d1.s, d3.s) > 0) {
                                // lose everything since the sum is <= 0
                                dp[u][i][j] = max(dp[u][i][j], mp(d1.f + d3.f - 1, d1.s + d3.s));
                            } else {
                                dp[u][i][j] = max(dp[u][i][j], mp(d1.f + d3.f - 1, d1.s + d3.s));
                            }
                        }
                    }
                }
            }
            dp2[u].resize(sub[u] + 1, mp(-1, -1));
            for (int i = 1; i <= sub[u]; i++) {
                dp2[u][i] = dp[u][num_children][i];
            }
            // set dp2[u][.] based on dp[u][num_children][.]
        };

        dfs1(1, 1);

        // looking at dp2
        // cout << "printint dp2\n";
        // for (int i = 1; i <= n; i++) {
        //     for (int j = 1; j <= sub[i]; j++) {
        //         print(dp2[i][j]);
        //     }
        //     cout << "\n";
        // }
        // cout << "\n";

        // looking at dp[3][.][.]

        // printdp(1, dp, sub, adj);
        // printdp(2, dp, sub, adj);
        // printdp(3, dp, sub, adj);
        // printdp(4, dp, sub, adj);

        int ans = dp2[1][m].f;
        cout << ans << "\n";
    }
} 