#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long long ll1;
const ll MAX=3e3+5;
ll MOD=1e9+7;
#define pb push_back
#define se second
#define fi first
#define sb __builtin_popcount
#define maxe max_element
#define mine min_element
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
#define debug4(x,y,z,w) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#w<<" :: "<<w<<endl;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define fbo find_by_order
#define ook order_of_key
#define up upper_bound
#define lb lower_bound
#define pq priority_queue
#define pll pair<ll,ll>
using namespace __gnu_pbds;
#define os tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define error 0.000000000000000001
ll add(ll a,ll b){return ((ll1)a+b)%MOD;}
ll mul(ll a,ll b){return ((ll1)a*b)%MOD;}
ll sub(ll a,ll b){return ((ll1)a-b+MOD)%MOD;}
#define boost               ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define dt pair<pll,ll>
pll dp[MAX][MAX];
vector<ll>v[MAX];
ll arr[MAX];
pll ad(pll a,pll b)
{
	return {a.fi+b.fi,a.se+b.se};
}
pll mx(pll a,pll b)
{
	if(a.fi>b.fi)return a;
	else if(a.fi==b.fi && a.se>b.se)return a;
	return b;
}
ll dfs(ll i,ll p)
{
	ll x=1;
	pll last[MAX],temp[MAX];
	for(ll i=0;i<MAX;i++)last[i]={0,0};
	for(ll u:v[i]){
		if(u==p)continue;
		x+=dfs(u,i);
		for(ll l=0;l<=x;l++)temp[l]={-1e17,-1e17};
		for(ll l=x-1;l>=0;l--){
			for(ll t=0;t<=l;t++){
				temp[l]=mx(temp[l],ad(dp[u][t],last[l-t]));
			}
		}
		for(ll l=0;l<x;l++)last[l]=temp[l];
	}
	//if(i==3 || i==4)debug(last[0].se);
	for(ll l=0;l<x;l++)last[l].se+=arr[i];
	//if(i==3 || i==4)debug(last[0].se);
	dp[i][x]={last[x-1].fi+((arr[i]>0)?1:0),0};
	for(ll l=0;l<x;l++){
		//if(i==1 && l==3)debug2(last[l-1].fi,last[l-1].se);
		if(l)dp[i][l]=mx(last[l],{last[l-1].fi+((last[l-1].se>0)?1:0),0});
		else dp[i][l]=last[l];
	}
	return x;
}
int main()
{
	//cout<<fixed<<setprecision(10);
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	ll t;
	cin>>t;
	while(t--){
	ll a,b;
	ll n,m;
	cin>>n>>m;
	for(ll i=0;i<=n;i++)v[i].clear();
	for(ll i=1;i<=n;i++)cin>>arr[i];
	for(ll i=1;i<=n;i++){
		cin>>a;
		arr[i]=a-arr[i];
	}
	for(ll i=0;i<MAX;i++)
		for(ll j=0;j<MAX;j++)
			dp[i][j]={-1e17,-1e17};
	for(ll i=0;i<n-1;i++){
		cin>>a>>b;
		v[a].pb(b);
		v[b].pb(a);
	}
	dfs(1,-1);
	cout<<dp[1][m].fi<<'\n';
}
	// for(ll i=1;i<=n;i++){
	// 	for(ll j=0;j<=3;j++)debug4(i,j,dp[i][j].fi,dp[i][j].se);
	// }

}
