#include<bits/stdc++.h>
#define p 998244353
using namespace std;
int dr()
{
	int xx=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9')xx=xx*10+ch-'0',ch=getchar();
	return xx*f;
}
int T,n,rt,a[400005],ans;
vector<int> bi[400005];int d[400005];
void add(int u,int v){bi[u].push_back(v),++d[v];}
int vi[15],pi[15],xh[15];
bool sscmp(const int &x,const int &y){return xh[x]<xh[y];}
int Fa[15];
void getfa(int u,int f)
{
	Fa[u]=f;
	for(int i=0,in=bi[u].size();i<in;i++)
	{
		int v=bi[u][i];
		if(v!=f)getfa(v,u);
	}
}
void cal(int u,int &x)
{
	x=min(x,a[u]),ans=(ans+x)%p;
	for(int i=0,in=bi[u].size();i<in;i++)
	{
		int v=bi[u][i];
		if(v!=Fa[u])cal(v,x);
	}
}
void ss(int t)
{
	if(t>n)
	{
		for(int i=1;i<=n;i++)xh[pi[i]]=i;
		for(int i=1;i<=n;i++)sort(bi[i].begin(),bi[i].end(),sscmp);
		for(int i=1;i<=n;i++){int x=a[i];cal(i,x);}
		return;
	}
	for(int i=1;i<=n;i++)if(!vi[i])pi[i]=i,vi[i]=1,ss(t+1),vi[i]=0;
}
bool check_line()
{
	int tn=0;
	for(int i=1;i<=n;i++)
	{
		if(d[i]>2)return false;
		if(d[i]==1)++tn;
	}
	return tn==2;
}
int la[400005],dfn;
void dfs(int u,int fa)
{
	la[++dfn]=a[u];
	for(int i=0,in=bi[u].size();i<in;i++)
	{
		int v=bi[u][i];
		if(v!=fa)dfs(v,u);
	}
}
int lxh[400005];
bool cmp(const int &x,const int &y){return la[x]<la[y];}
int lp[400005],rp[400005];
int f(int *P,int x)
{
	if(P[x]!=P[P[x]])P[x]=f(P,P[x]);
	return P[x];
}
int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	T=dr();
	while(T--)
	{
		n=dr(),rt=dr();
		for(int i=1;i<=n;i++)a[i]=dr();
		for(int i=1;i<n;i++)
		{
			int u=dr(),v=dr();
			add(u,v),add(v,u);
		}
		ans=0;
		if(n<=10)
		{
			getfa(rt,0);
			ss(1);
			int ny[15];
			ny[1]=1;
			for(int i=2;i<=n;i++)ny[i]=1ll*(p-p/i)*ny[p%i]%p;
			for(int i=1;i<=n;i++)ans=1ll*ans*ny[i]%p;
		}
		else if(check_line())
		{
			dfs(rt,0);
			for(int i=1;i<=n;i++)lxh[i]=i;
			sort(lxh+1,lxh+n+1,cmp);
			for(int i=0;i<=n+1;i++)lp[i]=rp[i]=i;
			for(int i=n;i;i--)
			{
				int w=lxh[i];
				int l=f(lp,w-1),r=f(rp,w+1);
				ans=(ans+1ll*(w-l)*(r-w)%p*la[w])%p;
			}
		}
		printf("%d\n",ans);
		for(int i=1;i<=n;i++)bi[i].clear(),d[i]=0;
	}
}
