#include <bits/stdc++.h>
using namespace std;
const int N = 4e5 + 5, M = N << 1;
#define MOD 998244353
typedef pair <int, int> pii;
int T, n, m, rt, u, v, inv1[N], inv2[N], a[N], b[N], Min[N], edgenum, Head[N], Next[M], vet[M], suf[N], now[N], dp[10005][10005], ans;
pii son[N];
void add(int u, int v) {
	Next[++edgenum] = Head[u];
	Head[u] = edgenum;
	vet[edgenum] = v;
}
int PLUS(int x, int y) {
	x += y;
	return x >= MOD ? x - MOD : x;
}
int qpow(int x, int y) {
	int t = 1;
	for (; y; y>>=1) {
		if (y & 1) t = 1ll * t * x % MOD;
		x = 1ll * x * x % MOD;
	} return t;
}
void dfs1(int u, int fa) {
	Min[u] = a[u];
	for (int e=Head[u]; e; e=Next[e]) {
		int v=vet[e];
		if (v ^ fa)
			dfs1(v, u), Min[u] = min(Min[u], Min[v]);
	}
}
void dfs2(int u, int fa) {
	for (int i=a[u]+1; i<=m; i++)
		dp[u][a[u]] = PLUS(dp[u][a[u]], dp[u][i]), dp[u][i] = 0;
	dp[u][a[u]] = PLUS(dp[u][a[u]], 1);
	for (int i=1; i<=m; i++)
		if (dp[u][i])
			ans = (ans + 1ll * dp[u][i] * b[i]) % MOD;
	suf[m] = dp[u][m];
	for (int i=m-1; i; i--)
		suf[i] = PLUS(suf[i+1], dp[u][i]);
	int cnt = 0;
	for (int e=Head[u]; e; e=Next[e]) {
		int v=vet[e];
		if (v ^ fa)
			son[++cnt] = pii (Min[v], v);
	}
	sort (son+1, son+1+cnt);
	for (int i=1; i<=m; i++)
		now[i] = 0;
	for (int i=2; i<=cnt; i++) {
		int v = son[i]. second;
		for (int j=1; j<Min[v]; j++)
			now[j] = (now[j] + 1ll * inv2[i] * dp[u][j]) % MOD;
		now[Min[v]] = (now[Min[v]] + 1ll * inv2[i] * suf[Min[v]]) % MOD;
	}
	for (int i=1; i<=m; i++)
		now[i] = (now[i] + 1ll * inv1[cnt] * dp[u][i]) % MOD;
	for (int i=1; i<=cnt; i++) {
		int v = son[i]. second;
		for (int j=1; j<Min[v]; j++)
			now[j] = (now[j] + 1ll * (MOD - inv2[i]) * dp[u][j]) % MOD;
		now[Min[v]] = (now[Min[v]] + 1ll * (MOD - inv2[i]) * suf[Min[v]]) % MOD;
		for (int j=1; j<=m; j++)
			dp[v][j] = now[j];
		for (int j=1; j<Min[v]; j++)
			now[j] = (now[j] + 1ll * inv2[i+1] * dp[u][j]) % MOD;
		now[Min[v]] = (now[Min[v]] + 1ll * inv2[i+1] * suf[Min[v]]) % MOD;
	}
	for (int e=Head[u]; e; e=Next[e])
		if (vet[e] ^ fa)
			dfs2(vet[e], u);
}
int main() {
	freopen ("dfs.in", "r", stdin);
	freopen ("dfs.out", "w", stdout);
	cin >> T;
	while (T--) {
		scanf ("%d%d", &n, &rt);
		edgenum = ans = 0;
		for (int i=1; i<=n; i++)
			Head[i] = 0;
		inv1[1] = 1;
		for (int i=2; i<=n; i++)
			inv1[i] = 1ll * (MOD - MOD / i) * inv1[MOD%i] % MOD;
		inv2[1] = 0;
		for (int i=2; i<=n; i++)
			inv2[i] = 1ll * inv1[i] * inv1[i-1] % MOD;
		for (int i=1; i<=n; i++)
			scanf ("%d", &a[i]), b[i] = a[i];
		sort (b+1, b+1+n), m = unique (b+1, b+1+n) - b - 1;
		for (int i=1; i<=n; i++)
			a[i] = lower_bound (b+1, b+1+m, a[i]) - b;
		for (int i=1; i<n; i++)
			scanf ("%d%d", &u, &v), add(u, v), add(v, u);
		for (int i=1; i<=m; i++)
			dp[rt][i] = 0;
		dfs1(rt, 0), dfs2(rt, 0);
		printf ("%d\n", ans);
	} return 0;
}