#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll T,n,root,a[400100],d[400100],u,v,m[400100],c[400100],l[400100],r[400100],ccc,ans,p=998244353,d2;
bool bb;
vector<ll>e[400100];
struct Node{
	ll a,x;
}b[400100];
bool cmp(Node a,Node b)
{
	return a.a>b.a;
}

ll exgcd(ll x,ll y,ll &a,ll &b)
{
	if (y==0)
	{
		a=1;
		b=0;
		return x;
	}
	ll k=exgcd(y,x%y,b,a);
	b-=(x/y)*a;
	return k;
}

ll gcdex(ll x)
{
	ll a,b;
	exgcd(x,p,a,b);
	return ((a%p)+p)%p;
}

ll dfsmx(ll x,ll pre)
{
	m[x]=a[x];
	for (ll i=0;i<e[x].size();i++)
		if (e[x][i]!=pre)
		m[x]=min(m[x],dfsmx(e[x][i],x));
	return m[x];
}
void adans(ll m)
{
	for (ll i=1;i<=m;i++)
		b[i].a=c[i],b[i].x=i;
	sort(b+1,b+1+m,cmp);
	for (ll i=1;i<=m;i++)
		l[i]=i-1,r[i]=i+1;
	for (ll i=1;i<=m;i++)
	{
		ans=(ans+(b[i].x-l[b[i].x])*(r[b[i].x]-b[i].x)*b[i].a)%p;
		ll l1=l[b[i].x],r1=r[b[i].x];
		r[l1]=r1,l[r1]=l1;
	}
	return;
}

void dfsans(ll x,ll pre,ll prmn,ll mn,ll dep)
{
	c[dep]=a[x];
	prmn=min(a[x],prmn);
	if (prmn<mn)
		ans=(ans+prmn)%p;
		else
			ans=(ans+prmn*d2+mn*d2)%p;
	for (ll i=0;i<e[x].size();i++)
		if (e[x][i]!=pre)
			dfsans(e[x][i],x,prmn,mn,dep+1);
	if (e[x].size()==1)
		adans(dep);
	return;
}

int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	d2=gcdex(2);
	scanf("%lld",&T);
	while (T--)
	{
		scanf("%lld%lld",&n,&root);
		for (ll i=1;i<=n;i++)
			scanf("%lld",&a[i]);
		for (ll i=1;i<=n-1;i++)
		{
			scanf("%lld%lld",&u,&v);
			e[u].push_back(v);
			e[v].push_back(u);
			d[u]++;
			d[v]++;
		}
		bb=1;
		for (ll i=1;i<=n;i++)
			if (d[i]>2)
			{
				bb=0;
				break;
			}
		if (d[root]==n-1)
		{
			ans=0;
			for (ll i=1;i<=n;i++)
				ans=(ans+a[i])%p;
			for (ll i=1;i<=root-1;i++)
				c[i]=a[i];
			for (ll i=root+1;i<=n;i++)
				c[i-1]=a[i];
			sort(c+1,c+n);
			ccc=0;
			for (ll i=1;i<=n-1;i++)
			{
				if (c[i]>a[root])
				{
					ccc=(ccc+a[root]*gcdex(i))%p;
					ans=(ans+ccc*(n-i))%p;
					break;
				}
				ans=(ans+ccc+c[i]*gcdex(i))%p;
				ccc=(ccc+((((c[i]*gcdex(i))%p)*gcdex(i+1))%p))%p;
			}
			printf("%lld\n",ans);
		}
		else if (bb)
		{
			dfsmx(root,0);
			ans=a[root];
			if (d[root]==1)
				dfsans(e[root][0],root,a[root],998244352,1);
			else
			{
				dfsans(e[root][0],root,a[root],m[e[root][1]],1);
				dfsans(e[root][1],root,a[root],m[e[root][0]],1);
				
			}	
			printf("%lld\n",ans);
		}
		else
		{
			printf("114514\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
