#include<bits/stdc++.h>
using namespace std;
const int Mod=998244353;
int T,n,root,a[400005];
vector<int> g[400005];
unsigned long long fpw(long long x,long long y)
{
	long long cur=x,tot=1;
	for(long long i=1;i<=y;i<<=1)
	{
		if(i&y)
			tot=cur*tot%Mod;
		cur=cur*cur%Mod;
	}
	return tot;
}
long long ans=0;
int dfs(int rt,int fa,int curmin)
{
	if(g[rt][0]==fa && g[rt].size()==1)
	{
		ans+=min(curmin,a[rt]);
		return min(curmin,a[rt]);
	}
	if(g[rt][0]==fa)
		swap(g[rt][0],g[rt][1]);
	if(curmin>a[rt])
	{
		ans+=a[rt];
		dfs(g[rt][0],rt,a[rt]);
	}
	else
	{
		ans+=curmin;
		dfs(g[rt][0],rt,curmin);
	}
	return min(curmin,a[rt]);
}
int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	int u,v;
	for(scanf("%d",&T);T;T--)
	{
		scanf("%d%d",&n,&root);
		for(int i=1;i<=n;i++)
			scanf("%d",&a[i]);
		for(int i=1;i<n;i++)
		{
			scanf("%d%d",&u,&v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		if(g[root].size()==2)
		{
			dfs(root,g[root][0],dfs(root,0,0x3f3f3f3f));
			dfs(root,g[root][0],dfs(root,0,0x3f3f3f3f));
			printf("%lld\n",ans%Mod*(Mod+1)/2%Mod);
		}
		else if(g[root].size()==1)
		{
			dfs(root,0,0x3f3f3f3f);
			printf("%lld\n",ans%Mod);
		}
		else
			while(1);
	}
	return 0;
}
