#include <bits/stdc++.h>
#define ll long long int
#define mp make_pair
#define pb push_back
#define ff first 
#define ss second
#define mod 1000000007
#define lim 100005
#define nfs_mw ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;

pair<int,ll> dp[3011][3011] = {};

pair<int,ll> maxim(pair<int,ll> a, pair<int,ll> b)
{
	pair<int,ll> ret = max(a,b);
	if(b.ff == a.ff)
		if(!(b.ss<=0 && a.ss<=0))
			ret.ss = a.ss + b.ss - ret.ss;
	return ret;
}

void dfs(int u, int pa, vector<int> gr[], ll w[], int sz[], int m)
{
	int i,j,&s = sz[u],cnt; s = 1;
	dp[u][1] = mp((w[u]>0), w[u]);
	for(int v:gr[u]) if(v!=pa) {
		dfs(v,u,gr,w,sz,m);
		vector<pair<int,ll>> tmp((min(s+sz[v],m)+1),mp(-1,1));
		for(i=1; i<=s; i++) {
			for(j=1; j<=sz[v] && (i+j-1)<=m; j++) {
				if(i+j<=m) tmp[i+j] = maxim(tmp[i+j], mp(dp[u][i].ff + dp[v][j].ff, dp[u][i].ss));
				cnt = dp[u][i].ff + dp[v][j].ff - (dp[u][i].ss>0) - (dp[v][j].ss>0) + ((dp[u][i].ss + dp[v][j].ss)>0);
				tmp[i+j-1] = maxim(tmp[i+j-1], mp(cnt, dp[u][i].ss + dp[v][j].ss));
			}
		}
		s = min(m, s+sz[v]);
		copy(tmp.begin(), tmp.end(), dp[u]);
	}
}

int main()
{
	nfs_mw;
	int i,t,m,n,x,y;
	cin>>t;
	while(t--){
		cin>>n>>m;
		int sz[n+1] = {};
		ll b[n+1],w[n+1];
		vector<int> gr[n+1];
		for(i=1; i<=n; i++) cin>>b[i];
		for(i=1; i<=n; i++) { cin>>w[i]; w[i] -= b[i]; }
		for(i=1; i<n; i++) {
			cin>>x>>y;
			gr[x].pb(y);
			gr[y].pb(x);
		}
		dfs(1,0,gr,w,sz,m);
		cout<<dp[1][m].ff<<"\n";
	}
}