#include<bits/stdc++.h>
using namespace std;
const int mod=998244353;
#define N 400040
typedef long long ll;
int n,rt,a[N],p[N];
int f[N],siz[N],now,wei[N],h[N],ban[N],ss[N],inv[N];
vector<int> G[N];
void dfs1(int u){
	siz[u]=1;
	ss[u]=0;
	for(auto v:G[u]){
		if(v==f[u])continue;
		f[v]=u;
		dfs1(v);
		siz[u]+=siz[v];
	}
	h[u]=siz[u]-1;
	now=(now+siz[u])%mod;
}
void dfs2(int u){
	if(ban[u])return;
	ban[u]=wei[u]=1;
	now=(now+mod-(h[u]+1))%mod;
	h[u]=0;
	for(auto v:G[u]){
		if(v==f[u])continue;
		dfs2(v);
	}
}

void Del(int u){
	//if(ban[u])return;
	//dfs2(u);
	ban[u]=1;
	for(int x=u;x;x=f[x]){
		wei[x]=1;
	}
	/*
	int las=wei[u],lw=h[u]+(!ban[u]);
	dfs2(u);
	int v=u;
	for(u=f[u];u;v=u,u=f[u]){
		int tmp=h[u]+(!ban[u]);
		now=(now+mod-(h[u]+(!ban[u])))%mod;
		h[u]=(h[u]+1LL*inv[ss[u]+1]*(h[v]+(!ban[v])-lw+mod))%mod;
		if(!las){
			h[u]=1LL*h[u]*(ss[u]+1)%mod;
			++ss[u];
			h[u]=1LL*h[u]*inv[ss[u]+1]%mod;
		}
		cerr<<" ?? "<<u<<" "<<ss[u]<<" "<<h[u]<<endl;
		now=(now+h[u]+(!ban[u]))%mod;
		las=wei[u];lw=tmp;
		wei[u]=1;
	}
	*/
}

void init(int n){
	inv[1]=1;
	for(int i=2;i<=n;++i){
		inv[i]=1LL*inv[mod%i]*(mod-mod/i)%mod;
	}
}
int dp[N];
void dfs3(int u){
	int cnt=0;
	for(auto v:G[u]){
		if(v==f[u])continue;
		dfs3(v);
		cnt+=wei[v];
	}
	dp[u]=0;
	for(auto v:G[u]){
		if(v==f[u])continue;
		if(wei[v]){
			dp[u]=(dp[u]+1LL*dp[v]*inv[cnt])%mod;
		}
		else{
			dp[u]=(dp[u]+1LL*dp[v]*inv[cnt+1])%mod;
		}
	}
	++dp[u];
	if(ban[u])dp[u]=0;
	now=(now+dp[u])%mod;
}
void Solve(){
	cin>>n>>rt;
	init(n);
	for(int i=1;i<=n;++i){
		cin>>a[i];
		p[i]=i;
		G[i].clear();
	}
	for(int i=1;i<n;++i){
		int u,v;
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	for(int i=1;i<=n;++i){
		f[i]=siz[i]=wei[i]=ban[i]=0;
	}
	dfs1(rt);
	sort(p+1,p+n+1,[&](int i,int j){return a[i]<a[j];});
	
	if((int)G[rt].size()==n-1){
		int ans=0;
		int leaf=n-1;
		for(int i=1;i<=n;++i){
			ans=(ans+1LL*now*(a[p[i]]-a[p[i-1]]))%mod;
			int u=p[i];
			ban[u]=1;
			if(u!=rt)--leaf;
			if(ban[rt]){
				now=leaf;
			}
			else{
				now=leaf+1;
				now=(now+1LL*inv[n-leaf]*leaf)%mod;
			}
		}
		cout<<ans<<'\n';
		return;
	}
	
	int ans=0;
	for(int i=1;i<=n;++i){
		ans=(ans+1LL*now*(a[p[i]]-a[p[i-1]]))%mod;
		Del(p[i]);
		now=0;
		dfs3(rt);
	}
	cout<<ans<<'\n';
}
int main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T;
	cin>>T;
	while(T--)Solve();
	return 0;
}
