#include <bits/stdc++.h>
#define rep(i, l, r) for(int i=l, _=r; i<=_; ++i)
using namespace std;
typedef long long ll;
inline int read() {
	int res=0; bool k=1; char ch;
	while(!isdigit(ch=getchar())) k=ch^45;
	do res=res*10+(ch&15); while(isdigit(ch=getchar()));
	return k? res: -res;
}
bool Mbe;
const int mN=4e5+9, mod=998244353;
inline void inc(int &x, const int y) {
	x=x+y<mod? x+y: x+y-mod;
}
inline int qpow(int x, int y) {
	int res=1;
	for(; y; y>>=1, x=(ll) x*x%mod) if(y&1) res=(ll) res*x%mod;
	return res;
}
int n, root, a[mN];
int oe, head[mN], e[mN*2][2];
inline void add(const int x, const int y) {
	e[++oe][0]=head[x], e[head[x]=oe][1]=y;
}
int fa[mN], d[mN], deg[mN], dfn_cl, be[mN], en[mN], smn[mN];
void dfs(int x) {
	be[x]=++dfn_cl, d[x]=d[fa[x]]+1, deg[x]=0, smn[x]=a[x];
	for(int t=head[x], y; y=e[t][1], t; t=e[t][0]) if(y^fa[x])
		fa[y]=x, dfs(y), ++deg[x], smn[x]=min(smn[x], smn[y]);
	en[x]=dfn_cl;
}

namespace solve1 {
#define in(x, y) (be[x]<=be[y] && en[y]<=en[x])
	const int mN=10+2, inf=0x3f3f3f3f;
	bool vis[mN];
	int dfs(int x, int now, int to) {
		if(x==to) return now;
		int res=0;
		for(int t=head[x], y; y=e[t][1], t; t=e[t][0]) if(y^fa[x] && !vis[y]) {
			if(in(y, to)) inc(res, dfs(y, min(a[y], now), to));
			else --deg[x], vis[y]=1, inc(res, dfs(x, min(now, smn[y]), to)), ++deg[x], vis[y]=0;
		}
		return (ll) res*qpow(deg[x], mod-2)%mod;
	}
	void main() {
		int res=0;
		rep(x, 1, n) rep(y, 1, n) if(in(x, y)) inc(res, dfs(x, a[x], y));
		printf("%d\n", res);
	}
#undef in
}

bool Men;
int main() {
//	cerr<<"memory: "<<(&Men-&Mbe>>20)<<" MB"<<endl;
	freopen("dfs.in", "r", stdin);
	freopen("dfs.out", "w", stdout);
	for(int T=read(); T--; ) {
		n=read(), root=read();
		oe=0, memset(head, 0, (n+1)*4);
		rep(i, 1, n) a[i]=read();
		rep(i, 2, n) {
			int x=read(), y=read();
			add(x, y), add(y, x);
		}
		d[fa[root]=0]=-1, dfn_cl=0, dfs(root);
		if(n<=10) solve1::main();
		else puts("114514");
	}
	return 0;
}
