#include<iostream>
#include<cstdio>
#include<algorithm>
#define mod (long long)998244353
using namespace std;
int T;
int n,x,y,root;
long long a[400005],jc[400005],jch[400005];
int du[400005];
long long kuaisu(long long x,int num){
	if(num==0) return 1;
	if(num==1) return x;
	long long sum=kuaisu(x,num/2);
	if(num%2) return sum*sum%mod*x%mod;
	return sum*sum%mod;
}
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	scanf("%d",&T);
	while(T--){
		scanf("%d%d",&n,&root);
		jc[0]=1;
		jc[1]=1;
		jch[0]=1;
		jch[1]=3;
		for(int i=1;i<=n;i++){
			jc[i]=jc[i-1]*i%mod;
			jch[i]=(jc[i-1]*i%mod+jc[i])%mod;
		}
		for(int i=1;i<=n;i++){
			scanf("%d",&a[i]);
			du[i]=0;
		//	head[i]=NIL;
		}
		for(int i=1;i<n;i++){
			scanf("%d%d",&x,&y);
			du[x]++;
			du[y]++;
//			addedge(x,y);
//			addedge(y,x);
		}
		long long ans=0,chu=0;
		if(du[root]==n-1){
			for(int i=1;i<=n;i++){
				if(a[i]>a[root]) a[i]=a[root];
			}
			sort(a+1,a+1+n);
			for(int i=1;i<n;i++){
				ans=(ans+a[i]*jch[n-i-1]%mod)%mod;
				chu+=jch[n-i-1];
			}
			printf("%lld\n",ans*kuaisu(chu,mod-2)%mod);
		}else{
			printf("0\n");
		}
	}
	return 0;
}
