#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int read(){
	char ch=getchar();int x=0;bool f=0;
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
	for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
	if(f)x=-x;return x;
}
const int maxn=8e5+5,mod=998244353;
int n,m,x,y,T,s[maxn],rt,fa[maxn],a[maxn],res=0,in[maxn],inv[maxn],ss[maxn];
pi st[maxn];vector<int>e[maxn];
void dfs(int x){
	s[x]=a[x];
	for(auto i:e[x])if(i^fa[x])fa[i]=x,dfs(i),s[x]=min(s[x],s[i]);
}
int Pow(int x,int y){int res=1;while(y){if(y&1)res=res*x%mod;x=x*x%mod;y=y/2;}return res;}
priority_queue<pi>q;
signed main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	T=read();
	while(T--){
		n=read(),rt=read();res=0;
		for(int i=1;i<=n;i++)a[i]=read(),e[i].clear(),fa[i]=0;
		for(int i=1;i<=n;i++)inv[i]=Pow(i,mod-2);
		for(int i=1;i<n;i++)x=read(),y=read(),e[x].pb(y),e[y].pb(x),in[x]++,in[y]++;
		dfs(rt);
		for(int i=1;i<=n;i++){
			int x=i;res+=a[x];res%=mod;
			while(!q.empty())q.pop();q.push(mp(-a[x],0));
			for(;fa[x];x=fa[x]){
				q.push(mp(-a[fa[x]],0));
				for(auto j:e[fa[x]])if(j!=fa[fa[x]]&&j!=x){
					q.push(mp(-s[j],fa[x]));
				}
				int tot=0,t=1;
				while(!q.empty()){
					st[++tot]=q.top();q.pop();
					
					pi p=st[tot];//cout<<-p.fi<<endl;
					if(!p.se){
						res=res-p.fi*t%mod;
						res%=mod;res=res+mod;res=res%mod;
						break;
					}
					else {
						
						res=res-p.fi*t%mod*inv[ss[p.se]+2]%mod;
						t=t-t*inv[ss[p.se]+2]%mod;ss[p.se]++;
						res%=mod;res=res+mod;res=res%mod;
					}
				}
				while(tot){
					q.push(st[tot]);ss[st[tot].se]=0;
					tot--;
				}
				res=(res%mod+mod)%mod;
			}
			
		}
		cout<<res<<endl;
	}
}
