#include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
const int inv2=(mod+1)/2;
const int N=400010;
int minx[N],a[N],ec[N],eb[N<<1],ea[N<<1],etot,fa[N],rt;
void addEdge(int x,int y){
	etot++;ea[etot]=y;eb[etot]=ec[x];ec[x]=etot;
}
int mul(int x,int y){
	return 1LL*x*y%mod;
}
int add(int x,int y){
	return x+y>=mod?x+y-mod:x+y;
}
int dec(int x,int y){
	return x-y<0?x-y+mod:x-y;
}
void dfs(int x,int f){
	minx[x]=a[x];fa[x]=f;
	for (int i=ec[x];i;i=eb[i]){
		int y=ea[i];
		if (y==f) continue;
		dfs(y,x);
		minx[x]=min(minx[x],a[y]);
	}
}
struct pt{
	int p,v;
	bool operator < (const pt &x) const {
		return v>x.v;
	}
	pt(int _v=0,int _p=0){
		v=_v;p=_p;
	}
};
int read(){
	int x=0,f=1;char c=getchar();
	while (c<'0' || c>'9'){
		if (c=='-') f=-f;c=getchar();
	}
	while (c>='0' && c<='9'){
		x=x*10+c-48;c=getchar();
	}
	return x*f;
}
priority_queue <pt> p;
vector <pt> v;
int ans,now;
void work(int x){
	ans=add(ans,now);
	if (x==rt) return;
	else{
		int f=fa[x],cp=0;
		while (!p.empty() && p.top().v>a[f]){
			pt tmp=p.top();p.pop();
			cp=add(cp,tmp.p);
			now=dec(now,mul(tmp.p,tmp.v));
		}
		p.push(pt(a[f],cp));now=add(now,mul(a[f],cp));
		for (int i=ec[f];i;i=eb[i]){
			int y=ea[i];
			if (y==x || y==fa[f]) continue;
			int cm=minx[y],cp=0;
			v.clear();
			while (!p.empty() && p.top().v>cm){
				pt tmp=p.top();p.pop();
				cp=add(cp,mul(tmp.p,inv2));
				now=dec(now,mul(tmp.v,tmp.p));
				tmp.p=mul(tmp.p,inv2);
				v.push_back(tmp);
			}
			p.push(pt(cm,cp));now=add(now,mul(cm,cp));
			for (int i=0;i<v.size();++i) p.push(v[i]),now=add(now,mul(v[i].p,v[i].v));
		}
		work(f);
	}
}
signed main(){
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	int T=read();
	while (T --> 0){
		int n=read();rt=read();
		etot=0;memset(ec,0,sizeof(ec));
		for (int i=1;i<=n;++i) a[i]=read();
		for (int i=1;i<=n-1;++i){
			int u=read(),v=read();
			addEdge(u,v);addEdge(v,u);
		}
		if (n>5000){
			for (int i=1;i<=n;++i) ans=add(ans,min(a[i],a[rt]));
			for (int i=1;i<=n;++i) ans=add(ans,a[i]);
			ans=dec(ans,a[rt]);
			printf("%d\n",ans);	
		}else{
			dfs(rt,0);ans=0;
			for (int i=1;i<=n;++i){
				while (!p.empty()) p.pop();p.push(pt(a[i],1));now=a[i];
				work(i);
			}
			printf("%d\n",ans);			
		}

	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}