#include<bits/stdc++.h>
using namespace std;

namespace FAST_IO
{
	#define Get getchar
	#define Put putchar
	template<typename tp=int>
	inline tp read(){tp res=0;char ch=' ';for(;ch<'0'||ch>'9';ch=Get());for(;ch>='0'&&ch<='9';ch=Get())res=(res<<3)+(res<<1)+(ch^48);return res;}
	template<typename tp>
	inline void write(tp a,char b='\n')
	{
		static int stk[21],top;
		for(top=0;a;a/=10)stk[++top]=a%10;
		for(;top;--top)Put(stk[top]^48);
		Put(b);
		return;
	}
}
using namespace FAST_IO;
const int N=4e5+10,mod=998244353;
int n,rt,num,head[N],fac[N],ifac[N],inv[N];
struct Edge{int to,next;}e[N<<1];
int mn[N],du[N],a[N];
inline void add(int x,int y){return e[++num]=(Edge){y,head[x]},head[x]=num,void();}
inline int add(int x){return x>=mod?x-mod:x;}
namespace FORCE{
	int id[11],t,fat[N],ans;
	void dfs_init(int now,int fa)
	{
		fat[now]=fa,mn[now]=a[now];
		for(int p=head[now],to=e[p].to;p;p=e[p].next,to=e[p].to)
			if(to!=fa)dfs_init(to,now),mn[now]=min(mn[now],mn[to]);
		return;
	}
	void dfs(int now,int fa,int P,int minn)
	{
		ans=(ans+1ll*P*min(a[now],minn))%mod;
		if(!head[now])return;
		vector<int>tto;
		for(int p=head[now],to=e[p].to;p;p=e[p].next,to=e[p].to)
			if(to!=fa)tto.push_back(to);
		int t=tto.size();
		for(int i=0;i<t;i++)id[i]=i;
		do{
			int pp=1,mi=min(a[now],minn);
			for(int i=0;i<t;i++)
			{
				pp=1ll*pp*inv[t-i]%mod;
				dfs(tto[id[i]],now,1ll*P*pp%mod,mi);
				mi=min(mi,mn[tto[id[i]]]);
			}
		}while(next_permutation(id,id+t));
		return;
	}
	void main()
	{
		ans=0;
		dfs_init(rt,rt);
		for(int i=1;i<=n;i++)
			dfs(i,fat[i],1,a[i]);
		cout<<ans<<'\n';
		return;
	}
}
int main()
{
	freopen("dfs.in","r",stdin);
	freopen("dfs.out","w",stdout);
	fac[0]=1;for(int i=1;i<N;i++)fac[i]=1ll*fac[i-1]*i%mod;
	inv[0]=inv[1]=1;for(int i=2;i<N;i++)inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;
	ifac[0]=1;for(int i=1;i<N;i++)ifac[i]=1ll*ifac[i-1]*inv[i]%mod;
	int T=read();
	while(T--)
	{
		n=read(),rt=read(),num=0;
		memset(head,0,sizeof(int)*(n+1));
		memset(mn,0,sizeof(int)*(n+1));
		memset(du,0,sizeof(int)*(n+1));
		for(int i=1;i<=n;i++)a[i]=read();
		for(int i=1,x,y;i<n;i++)x=read(),y=read(),du[x]++,du[y]++,add(x,y),add(y,x);
		FORCE::main();
	}

	return 0;
}

