#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
using namespace std;

void ckmax(int &a,int b){a=(a>b?a:b);}
void ckmin(int &a,int b){a=(a<b?a:b);}

int read()
{
	int f=1,num=0;char ch=getchar();
	while(!((ch<='9'&&ch>='0')||ch=='-'))ch=getchar();
	if (ch=='-')f=-1,ch=getchar();
	while(ch<='9'&&ch>='0')num=num*10+ch-'0',ch=getchar();
	return num*f;
}

const int Mod=998244353;
const int M=4e5+10;
int n,rt,a[M],f[M],vis[M],fa[M],g[M],inv[M],cnt[M],s1[M],s2[M];
pair<int,int>p[M];
vector<int>e[M];

int poww(int a,int b=Mod-2)
{
	int res=1;
	while(b)
	{
		if (b&1)res=res*a%Mod;
		a=a*a%Mod,b>>=1;
	}return res;
}

void dfs(int u,int ff)
{
	fa[u]=ff,g[u]=1;
	for (auto v:e[u])
		if (v!=ff)dfs(v,u),g[u]+=g[v],s1[u]+=g[v];
}

void work(int u)
{
	int tmp=g[u];g[u]=0;vis[u]=1;
	while(u!=rt)
	{
		int ff=fa[u];
		if (vis[ff])break;
		int tmp2=g[ff];
		if (f[u])
			g[ff]=(g[ff]+inv[cnt[ff]-f[u]+1]*(g[u]-tmp+Mod)%Mod+Mod)%Mod,s2[ff]=(s2[ff]+g[u]-tmp+Mod)%Mod;
		if (!f[u])
		{
			f[u]=1,cnt[ff]++;
			s1[ff]=(s1[ff]-tmp+Mod)%Mod,s2[ff]=(s2[ff]+g[u])%Mod;
			g[ff]=(1+inv[cnt[ff]+1]*s1[ff]+inv[cnt[ff]]*s2[ff])%Mod;
		}tmp=tmp2,u=ff;
	}
}

void solve()
{
	n=read(),rt=read();
	for (int i=1;i<=n;i++)a[i]=read(),e[i].clear(),p[i]=mp(a[i],i),inv[i]=poww(i),vis[i]=cnt[i]=f[i]=g[i]=s1[i]=s2[i]=0;
	sort(p+1,p+1+n);
	for (int i=1;i<n;i++)
	{
		int u=read(),v=read();
		e[u].pb(v),e[v].pb(u);
	}dfs(rt,0);int ans=0;
	for (int i=1;i<=n;i++)ans+=g[i];
	ans=ans%Mod*p[1].x%Mod;
	for (int i=1;i<=n;i++)
	{
		int l=i,res=0;
		while(l<=n&&p[l].x==p[i].x)l++;
		if (l>n)break;
		for (int j=i;j<l;j++)work(p[j].y);
		for (int j=1;j<=n;j++)res=(res+g[j])%Mod;
		ans=(ans+(p[l].x-p[i].x+Mod)*res)%Mod,i=l-1;
	}
	cout<<ans<<'\n';
}

signed main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
//	freopen("dfs_ex2.in","r",stdin);
	int T=read();
	while(T--)solve();
	return 0;
}
/*
1
6 1
5 2 4 1 3 6
1 2
1 6
2 3
2 4
4 5
*/
