// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define sz(c) ((ll)c.size())
#define ordered_set                            \
    tree<ll, null_type, less<ll>, rb_tree_tag, \
         tree_order_statistics_node_update>
const ll INF = 1e12;

vvi g;
vvii dp;
vi cost, size;
ll n, m;

void dfs(ll u, ll p) {
    dp[u][0] = {0, cost[u]};
    size[u] = 1;
    for (auto it : g[u]) {
        if (it == p) {
            continue;
        }

        dfs(it, u);
        size[u] += size[it];
        vii tmp(m + 1, {-INF, 0});
        for (int i = 0; i <= min(size[u], m); i++) {
            for (int j = 0; j <= min(size[it], m) && i + j <= m; j++) {
                tmp[i + j] = max(tmp[i + j], {dp[u][i].ff + dp[it][j].ff,
                                              dp[u][i].ss + dp[it][j].ss});
            }
        }

        for (int i = 0; i <= min(size[u], m); i++) {
            for (int j = 0; j <= min(size[it], m) && i + j + 1 <= m; j++) {
                tmp[i + j + 1] = max(
                    tmp[i + j + 1],
                    {dp[u][i].ff + dp[it][j].ff + ((dp[it][j].ss > 0) ? 1 : 0),
                     dp[u][i].ss});
            }
        }
        dp[u] = tmp;
    }
}

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

    ll t;
    cin >> t;
    while (t--) {
        g.clear(), cost.clear(), dp.clear(), size.clear();

        cin >> n >> m;
        g.resize(n), cost.resize(n), dp.resize(n), size.resize(n);
        for (auto &it : cost) {
            cin >> it;
        }

        for (int i = 0; i < n; i++) {
            ll x;
            cin >> x;
            cost[i] = (x - cost[i]);
        }

        for (int i = 0; i < n - 1; i++) {
            ll x, y;
            cin >> x >> y;
            x--, y--;
            g[x].pb(y);
            g[y].pb(x);
        }

        dp.resize(n);
        for (auto &it : dp) {
            it.resize(m + 1, {-INF, 0});
        }

        dfs(0, 0);
        cout << dp[0][m].ff + (dp[0][m - 1].ss > 0 ? 1 : 0) << "\n";
    }
}
