#include<cstdio>
#include<cstring>
#include<cctype>
#include<utility>
#include<algorithm>
#include<cmath>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int ver[6001],nxt[6001],head[3001],ans,t,n,m,f[3001][3001],g[3001][3001],a[3001],x,y,len[3001],h[3001],p[3001];
inline void check(int x,int y,int &xx,int &yy) {
	if(x>xx||(x==xx&&y>yy)) xx=x,yy=y;
}
void dfs(int x,int fa) {
	len[x]=1,f[x][1]=0,g[x][1]=a[x];
	for(res i=head[x];i;i=nxt[i]) {
		if(ver[i]==fa) continue;
		dfs(ver[i],x);
		int now=min(len[x],m);
		for(res j=1;j<=now;++j) h[j]=f[x][j],p[j]=g[x][j],f[x][j]=g[x][j]=-1e9;
		for(res j=1;j<=now;++j) {
			for(res l=1;l<=len[ver[i]]&&l<=m-j;++l) {
			  	check(h[j]+f[ver[i]][l]+(g[ver[i]][l]>0),p[j],f[x][j+l],g[x][j+l]);
			  	check(h[j]+f[ver[i]][l]+(p[j]>0),g[ver[i]][l],f[x][j+l],g[x][j+l]);
			}
			for(res l=1;l<=len[ver[i]]&&l<=m-j+1;++l) check(h[j]+f[ver[i]][l],p[j]+g[ver[i]][l],f[x][j+l-1],g[x][j+l-1]);
		}
		len[x]+=len[ver[i]];
	}
}
inline void add(int x,int y) {ver[++ans]=y,nxt[ans]=head[x],head[x]=ans;}
int main()
{
	read(t);
	while(t--) {
		read(n),read(m);
		for(res i=1;i<=n;++i) read(a[i]),a[i]=-a[i];
		for(res i=1;i<=n;++i) read(x),a[i]+=x;
		for(res i=1;i<n;++i) read(x),read(y),add(x,y),add(y,x);
		dfs(1,0),print(f[1][m]+(g[1][m]>0),'\n');
		for(res i=1;i<=n;++i)
		  for(res j=1;j<=m;++j) f[i][j]=g[i][j]=0;
		memset(head,0,n+1<<2),ans=0;
	}
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 