#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define scan(x) do{while((x=getchar())<'0'); for(x-='0'; '0'<=(_=getchar()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define complete_unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define all(a) a.begin(),a.end()
#define println printf("\n");
#define readln(x) getline(cin,x);
#define pb push_back
#define endl "\n"
#define INT_INF 0x3f3f3f3f
#define LL_INF 0x3f3f3f3f3f3f3f3f
#define EPS 1e-9
#define MOD 1000000007
#define MOD2 1494318097
#define SEED 131
#define mp make_pair
#define fastio cin.tie(0); cin.sync_with_stdio(0);

#define MAXN 3005

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef pair<int,pii> triple;
typedef int8_t byte;

mt19937 g1(chrono::steady_clock::now().time_since_epoch().count());

int randint(int a, int b){return uniform_int_distribution<int>(a, b)(g1);}
ll randlong(ll a,ll b){return uniform_int_distribution<long long>(a, b)(g1);}

ll gcd(ll a, ll b){return b == 0 ? a : gcd(b, a % b);}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
ll fpow(ll  b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}

int T,num_nodes,K,sz[MAXN];
ll vals[MAXN];
pair<int,ll> dp[MAXN][MAXN];
vector<int> connections[MAXN];

void solve(int node, int prev){
    sz[node] = 1;
    int cc = 0;
    for(int check:connections[node]) cc+=(check!=prev);
    if(cc == 0){
        if(vals[node] > 0) dp[node][1] = mp(1,0), dp[node][0] = mp(0,vals[node]);
        else dp[node][1] = mp(0,0), dp[node][0] = mp(0,vals[node]);
        return;
    }
//    if(node == 3){
//        printf("\n");
//    }
    for(int check:connections[node]){
        if(check == prev) continue;
        solve(check,node);
        if(sz[node] == 1){
            for(int ch=0; ch<=sz[check]; ch++)
                dp[node][ch] = dp[check][ch];
            sz[node]+=sz[check];
            continue;
        }
        pair<int,ll> tmp[MAXN];
        for(int i=0; i<=num_nodes; i++)
            tmp[i] = mp(-LL_INF,-LL_INF);
        for(int ch=0; ch<=sz[check]; ch++){
            for(int m=0; m<=sz[node]; m++){
                pair<int,ll> nxt = mp(dp[check][ch].first+dp[node][m].first,dp[check][ch].second+dp[node][m].second);
                tmp[ch+m] = max(tmp[ch+m],nxt);
            }
        }
        for(int i=0; i<=num_nodes; i++)
            dp[node][i] = max(dp[node][i],tmp[i]);
        sz[node]+=sz[check];
    }
    for(int i=num_nodes; i>=0; i--){
        dp[node][i].second+=vals[node];
        if(dp[node][i].second > 0) dp[node][i+1] = max(dp[node][i+1],mp(dp[node][i].first+1,0LL));
        dp[node][i+1] = max(dp[node][i+1],mp(dp[node][i].first,0LL));
    }
}

int main(){
    scanf("%d",&T);
    while(T--){
        scanf(" %d %d",&num_nodes,&K);
        for(int i=1; i<=num_nodes; i++){
            scanf(" %lld",&vals[i]);
            connections[i].clear();
        }
        for(int i=1; i<=num_nodes; i++){
            ll v; scanf(" %lld",&v);
            vals[i] = v-vals[i];
            for(int k=0; k<=K; k++)
                dp[i][k] = mp(-LL_INF,-LL_INF);
        }
        for(int i=1; i<num_nodes ;i++){
            int a,b; scanf(" %d %d",&a,&b);
            connections[a].pb(b);
            connections[b].pb(a);
        }
        solve(1,-1);
        int res = dp[1][K-1].first;
        if(dp[1][K].second >= 0) res = max(res,dp[1][K].first);
        printf("%d\n",res);
    }
}
/*
1
4 3
10 160 70 50
70 111 111 0
1 2
2 3
3 4
ans=2

1
2 1
143 420
214 349
2 1
ans=0
 */