/* Author: Thallium54 {{{
 * Blog: https://blog.tgc-thallium.com/
 * Code library: https://github.com/thallium/acm-algorithm-template
 * }}}*/
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end() //{{{
#ifndef LOCAL // https://github.com/p-ranav/pprint
#define de(...)
#define de2(...)
#endif
using ll = long long;
using pii = pair<int, int>; //}}}

void test_case() {
    int n, m;
    cin>>n>>m;
    vector<vector<int>> g(n);
    vector<int> votes(n);
    for (int i=0; i<n; i++) {
        int x;
        cin>>x;
        votes[i]-=x;
    }
    for (int i=0; i<n; i++) {
        int x;
        cin>>x;
        votes[i]+=x;
    }

    for (int i=1; i<n; i++) {
        int u, v;
        cin>>u>>v;
        u--, v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    vector dp(n, vector<pair<int, ll>>(n+1));
    vector<int> sz(n+1, 1);
    vector<pair<int, ll>> f(n+1);
    auto dfs=[&](auto& slf, int u, int p) -> void {
        dp[u][1]={votes[u]>0, votes[u]};
        for (auto v : g[u]) {
            if (v==p) continue;
            slf(slf, v, u);
            f.assign(n+1, {});
            for (int i=sz[u]; i>=1; i--) {
                for (int j=1; j<=sz[v]; j++) {
                    f[i+j]=max(f[i+j], {dp[u][i].first+dp[v][j].first, dp[u][i].second});
                    f[i+j-1]=max(f[i+j-1], {dp[u][i].first+dp[v][j].first-1-(dp[u][i].second+dp[v][j].second<=0),
                            dp[u][i].second+dp[v][j].second});
                }
            }
            dp[u].swap(f);
            sz[u]+=sz[v];
        }
    };
    dfs(dfs, 0, 0);
    cout<<dp[0][m].first<<'\n';

};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int tt=1;
    cin >> tt;
    while (tt--) {
        test_case();
    }
}
