#include<bits/stdc++.h>
using namespace std;
#define N 400005
#define mod 998244353
#define ll long long
int t,n,rt,x,y,ans,a[N],fa[N],dfn[N],sz[N];
int inv[N],id[N],vis[N],cnt[N],Vis[N],Cnt[N],g[N],f[N];
vector<int>e[N];
int read(){
	int x=0;char c=getchar();
	while ((c<'0')||(c>'9'))c=getchar();
	while ((c>='0')&&(c<='9'))x=x*10+c-'0',c=getchar();
	return x;
}
int lowbit(int k){
	return (k&(-k));
}
void update(int k){
	while (k<=n)cnt[k]++,k+=lowbit(k);
}
int query(int k){
	int ans=0;
	while (k)ans+=cnt[k],k^=lowbit(k);
	return ans;
}
int query(int l,int r){
	return query(r)-query(l-1);
}
bool cmp(int x,int y){
	return a[x]<a[y];
}
void dfs(int k,int f){
	fa[k]=f,dfn[k]=++dfn[0],sz[k]=1,Cnt[k]=0;
	for(int i:e[k])
		if (i!=f)dfs(i,k),sz[k]+=sz[i],Cnt[k]++;
}
void calc(int k,int fa,int pos){
	if ((dfn[pos]<dfn[k])||(dfn[k]+sz[k]<=dfn[pos]))return;
	g[k]=vis[k],f[k]=0;
	for(int i:e[k])
		if (i!=fa){
			calc(i,k,pos);
			if (vis[k])g[k]=(g[k]+(ll)g[i]*inv[Cnt[k]+Vis[i]])%mod;
			f[k]=(f[k]+f[i])%mod;
		}
	f[k]=(f[k]+g[k])%mod;
}
namespace Subtask1{
	int s,fa[N],sz[N];
	bool check(){
		if (e[rt].size()>1)return 0;
		for(int i=1;i<=n;i++)
			if (e[i].size()>2)return 0;
		return 1;
	}
	int C(int k){
		return (ll)k*(k+1)%mod*(mod+1>>1)%mod;
	}
	int find(int k){
		if (k==fa[k])return k;
		return fa[k]=find(fa[k]);
	}
	void merge(int x,int y){
		x=find(x),y=find(y);
		s=(s-(C(sz[x])+C(sz[y]))%mod+mod)%mod;
		fa[x]=y,sz[y]+=sz[x],s=(s+C(sz[y]))%mod;
	}
	void main(){
		s=0;
		for(int i=1;i<=n;i++)fa[i]=i,sz[i]=0;
		for(int i=n;i;i--){
			int k=dfn[id[i]];
			vis[k]=1,sz[k]++,s=(s+1)%mod;
			if ((k>1)&&(vis[k-1]))merge(k,k-1);
			if ((k<n)&&(vis[k+1]))merge(k,k+1);
			ans=(ans+(ll)s*(a[id[i]]-a[id[i-1]]))%mod;
		}
	}
};
namespace Subtask2{
	int cnt,flag,s;
	void main(){
		cnt=flag=0;
		for(int i=n;i;i--){
			if (id[i]!=rt)cnt++;
			else flag=1;
			if (!flag)ans=(ans+(ll)cnt*(a[id[i]]-a[id[i-1]]))%mod;
			else ans=(ans+((ll)cnt*inv[n-cnt]+cnt+1)%mod*(a[id[i]]-a[id[i-1]]))%mod;
		}
	}
};
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	inv[0]=inv[1]=1;
	for(int i=2;i<N;i++)inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod;
	t=read();
	while (t--){
		n=read(),rt=read(),ans=0;
		for(int i=1;i<=n;i++)a[i]=read();
		for(int i=1;i<=n;i++)e[i].clear();
		for(int i=1;i<n;i++){
			x=read(),y=read();
			e[x].push_back(y),e[y].push_back(x);
		}
		dfn[0]=0,dfs(rt,0);
		for(int i=1;i<=n;i++)id[i]=i;
		sort(id+1,id+n+1,cmp);
		for(int i=1;i<=n;i++)vis[i]=cnt[i]=Vis[i]=g[i]=f[i]=0;
		if (Subtask1::check()){
			Subtask1::main();
			printf("%d\n",ans);
			continue;
		}
		if (e[rt].size()==n-1){
			Subtask2::main();
			printf("%d\n",ans);
			continue;
		}
		for(int i=n;i;i--){
			vis[id[i]]=1,update(dfn[id[i]]);
			for(int j=id[i];j!=rt;j=fa[j]){
				if (query(dfn[j],dfn[j]+sz[j]-1)!=sz[j])break;
				Vis[j]=1,Cnt[fa[j]]--;
			}
			calc(rt,0,id[i]);
			ans=(ans+(ll)f[rt]*(a[id[i]]-a[id[i-1]]))%mod;
		}
		printf("%d\n",ans);
	}
	return 0;
}
