#include<bits/stdc++.h>
using namespace std;
const int Max_N=4e5,Mod=998244353;
int T,n,rt,Num,ans,a[Max_N+5],lin[Max_N+5],fa[Max_N+5],Inv[Max_N+5];
struct Edge{ int Id,Next; } e[Max_N*2+5];
void Insert(int x,int y){
	e[++Num].Next=lin[x]; lin[x]=Num; e[Num].Id=y;
}
int Read(){
	int num=0; char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar());
	for(;ch>='0'&&ch<='9';num=num*10+ch-'0',ch=getchar());
	return num;
}
void Pre(int x){
	for(int i=lin[x];i;i=e[i].Next){
		if(e[i].Id==fa[x]) continue;
		fa[e[i].Id]=x; Pre(e[i].Id);
	}
}
void dfs(int r,int x,int val,int p,int s,int fir){
	if(!fir) ans=(1ll*p*val+ans)%Mod;
	int tot=0;
	for(int i=lin[x];i;i=e[i].Next)
	 if(e[i].Id!=fa[x]&&!((1<<(e[i].Id-1))&s)) ++tot;
	if(tot==0){
		if(r==x) return;
		dfs(r,fa[x],val,p,s,1);
	} else {
		for(int i=lin[x];i;i=e[i].Next)
	 	 if(e[i].Id!=fa[x]&&!((1<<(e[i].Id-1))&s))
	 	  dfs(r,e[i].Id,min(val,a[e[i].Id]),1ll*p*Inv[tot]%Mod,s|(1<<(e[i].Id-1)),0);
	}
}
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	T=Read();
	for(;T--;){
		n=Read(),rt=Read();
		for(int i=1;i<=n;i++) a[i]=Read();
		Inv[0]=Inv[1]=1;
		for(int i=2;i<=n;i++) Inv[i]=1ll*Inv[Mod%i]*(Mod-Mod/i)%Mod;
		for(int i=1;i<n;i++){
			int x=Read(),y=Read();
			Insert(x,y),Insert(y,x);
		}
		fa[rt]=0; Pre(rt); ans=0;
		for(int i=1;i<=n;i++) dfs(i,i,a[i],1,1<<(i-1),0);
		cout<<ans<<endl;
		Num=0; for(int i=1;i<=n;i++) lin[i]=0;
	}
	return 0;
}
