#include <bits/stdc++.h>
using namespace std;
#define file(x) freopen(x".in", "r", stdin), freopen(x".out", "w", stdout);
#define rep(i, a, b) for(ll i = (a); i <= (b); ++ i)
#define per(i, a, b) for(ll i = (a); i >= (b); -- i)
#define pb push_back
typedef long long ll;
const int maxn = 8e5 + 100;
const ll mod = 998244353;
ll read()
{
	ll x;
	scanf("%lld", &x);
	return x;
}

ll chmin(ll &a, ll b){return a = min(a, b);}
ll chmax(ll &a, ll b){return a = max(a, b);}

ll t, n, rt, ans;

ll a[maxn], b[maxn], tot, c[maxn];

vector <ll> edge[maxn];

ll mn[maxn], sz[maxn];

ll power(ll a, ll b)
{
	ll ret = 1;
	for(; b; b >>= 1, (a *= a) %= mod) if(b & 1) (ret *= a) %= mod;
	return ret;
}

ll fac[maxn], inv[maxn];

void dfs1(ll now, ll fa)
{
	mn[now] = c[now], sz[now] = 1;
	for(ll to : edge[now])
	{
		if(to == fa) continue;
		dfs1(to, now);
		chmin(mn[now], mn[to]);
		sz[now] += sz[to];
	}
	(ans += sz[now] * b[1]) %= mod;
}

ll f[maxn];

void dfs2(ll now, ll fa, ll num)
{
	f[now] ++;
	if(c[now] <= num) f[now] = 0;
	(ans += f[now] * (b[num + 1] - b[num])) %= mod;
	ll tmp = 1;
	for(ll to : edge[now]) if(to != fa && mn[to] <= num) tmp ++;
	for(ll to : edge[now])
	{
		if(to == fa) continue;
		f[to] = f[now];
		if(mn[to] <= num) (f[to] *= inv[tmp - 1] * fac[tmp - 2] % mod) %= mod;
		else (f[to] *= inv[tmp] * fac[tmp - 1] % mod) %= mod;
		dfs2(to, now, num);
	}
}

void init()
{
	ll n = 8e5;
	fac[0] = 1;
	rep(i, 1, n) fac[i] = fac[i - 1] * i % mod;
	inv[n] = power(fac[n], mod - 2);
	per(i, n, 1) inv[i - 1] = inv[i] * i % mod;
}

signed main()
{
	file("dfs");
	t = read();
	init();
//	t = 1;
	while(t --)
	{
		n = read(), rt = read();
		rep(i, 1, n) vector <ll> ().swap(edge[i]);
		tot = 0;
		rep(i, 1, n) a[i] = read(), b[++ tot] = a[i];
		sort(b + 1, b + tot + 1), tot = unique(b + 1, b + tot + 1) - b - 1;
		rep(i, 1, n) c[i] = lower_bound(b + 1, b + tot + 1, a[i]) - b;
		rep(i, 1, n - 1)
		{
			ll u = read(), v = read();
			edge[u].pb(v), edge[v].pb(u);
		}
		ans = 0;
		dfs1(rt, 0);
//		cout << ans << endl;
		rep(i, 1, tot - 1)
		{
			ll last = ans;
			f[rt] = 0, dfs2(rt, 0, i);//, cerr << ans << endl;
//			cout << (ans + mod - last) * 6 % mod << endl;
		}
		printf("%lld\n", ans);
	}
	return 0;
}

/*
1
3 1
1 100000000 100000
1 2
1 3

*/