// Fresh Peach Heart Shower
#include <bits/stdc++.h>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof(x))
#define MP std::make_pair
#define ALL(x) (x).begin(),(x).end()
#define ln std::putchar('\n')
#define lsp std::putchar(' ')
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,b,a) for(int i=(b);i>=(a);--i)
#define dprintf(x...) fprintf(stderr,x)
typedef std::pair<int,int> pii;
typedef std::vector<int> poly;
template <class t> inline void read(t &s)
{
	s=0;
	char c=getchar();
	signed f=0;
	while(!isdigit(c))f|=c=='-',c=getchar();
	while(isdigit(c))s=(s<<3)+(s<<1)+(c^48),c=getchar();
	if(f)s=-s;
}
template <class t> inline void write(t x)
{
	if(!x)return std::putchar('0'),void();
	if(x<0)std::putchar('-'),x=-x;
	static signed st[50],tp=0;
	while(x)st[++tp]=x%10,x/=10;
	while(tp)std::putchar(st[tp--]^48);
}
inline void setIn(std::string s){freopen(s.c_str(),"r",stdin);}
inline void setOut(std::string s){freopen(s.c_str(),"w",stdout);}
inline void setIO(std::string s){setIn(s+".in"),setOut(s+".out");}
template <class t> inline bool ckmin(t&x,t y){if(x>y)return x=y,1;return 0;}
template <class t> inline bool ckmax(t&x,t y){if(x<y)return x=y,1;return 0;}
inline int lowbit(int x){return x&(-x);}
typedef long long ll;
const int MaxN=4e5+50;
const ll p=998244353;
inline ll fpow(ll a,int b)
{
	ll ret=1;
	for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;
	return ret;
}
struct CC
{
	ll f[MaxN],inv[MaxN],Inv[MaxN];
	CC()
	{
		f[0]=1;
		rep(i,1,MaxN-1)f[i]=f[i-1]*i%p;
		inv[MaxN-1]=fpow(f[MaxN-1],p-2);
		per(i,MaxN-2,0)inv[i]=inv[i+1]*(i+1)%p;
		Inv[0]=1;
		rep(i,1,MaxN-1)Inv[i]=f[i-1]*inv[i]%p;
	}
}C;
poly E[MaxN];
ll f[MaxN],g[MaxN],lstv[MaxN],magius;
int a[MaxN],F[MaxN],died[MaxN],bad[MaxN],n,Rt;
struct Dsu
{
	int f[MaxN];
	inline int getf(int x){return f[x]==x?x:f[x]=getf(f[x]);}
	inline void init(){rep(i,1,n)f[i]=i;}
}dsu;
inline void UpdG(int u,int x){(magius+=p-g[u])>=p&&(magius-=p),(magius+=g[u]=x)>=p&&(magius-=p);}
inline void AddG(int u,int x){(magius+=x)>=p&&(magius-=p),(g[u]+=x)>=p&&(g[u]-=p);}
inline void dfs(int u,int fa)
{
	AddG(u,1),F[u]=fa;
	for(auto v:E[u])if(v!=fa)dfs(v,u),AddG(u,lstv[v]=g[v]);
}
inline void upd(int u)
{
	died[u]=1,UpdG(u,0);
	for(int fa=F[u];fa;u=fa,fa=F[u])
	{
		if(!died[fa])for(auto v:E[fa])if(v!=F[fa])AddG(fa,p-lstv[v]);
		bad[fa]-=!f[u],f[u]=0,++bad[fa];
		if(!died[fa])for(auto v:E[fa])if(v!=F[fa])AddG(fa,lstv[v]=C.Inv[bad[fa]+f[v]]*g[v]%p);
	}
}
poly pos[MaxN],dr;
inline int get(int x){return std::lower_bound(ALL(dr),x)-dr.begin()+1;}
inline void clear()
{
	dr.clear();
	rep(i,0,n)E[i].clear(),pos[i].clear();
	rep(i,0,n)bad[i]=died[i]=0,f[i]=1,g[i]=0;
	magius=0;
}
std::mt19937 rnd(time(0));
inline void work()
{
	read(n),read(Rt);
	dsu.init();
//	dprintf("N %d\n",n);
	clear();
	rep(i,1,n)read(a[i]),dr.pb(a[i]);
	std::sort(ALL(dr)),dr.erase(std::unique(ALL(dr)),dr.end());
	rep(i,1,n)pos[get(a[i])].pb(i);
	int u,v;
	rep(i,1,n-1)read(u),read(v),E[u].pb(v),E[v].pb(u);

	dfs(Rt,0);

	ll ans=0,lst=0;
	rep(i,0,(int)dr.size()-1)
	{
		for(auto j:pos[i])upd(j);
		(ans+=magius*(dr[i]-lst))%=p,lst=dr[i];
	}
	write(ans),ln;
}
signed main(void)
{
	setIO("dfs");

	int t;read(t);
	while(t--)work();
	return 0;
}





