#include <bits/stdc++.h>

const int N = 4e5 + 10, mod = 998244353;

inline void upd(int &a, int b) { a = a + b >= mod ? a + b - mod : a + b; }

inline int read()
{
	int x = 0, f = 0; char ch = getchar();
	while (!isdigit(ch)) f |= ch == '-', ch = getchar();
	while ( isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return f ? -x : x;
}

int f[N], p[N], par[N], a[N], id[N], inv[N], ban[N], vis[N];

std::vector<int> T[N];

inline void dfs(int u, int fa)
{
	f[u] = 1, p[u] = ban[u] = vis[u] = 0, par[u] = fa;
	for (auto v: T[u]) if (v != fa) dfs(v, u), f[u] += f[v];
}

inline void DFS(int u, int fa)
{
	for (auto v: T[u]) if (v != fa) DFS(v, u);
	if (!ban[u])
	{
		int x = 0;
		f[u] = 1;
		for (auto v: T[u]) if (v != fa) x += vis[v];
		for (auto v: T[u]) if (!ban[v] && v != fa) upd(f[u], 1LL * inv[x - vis[v] + 1] * f[v] % mod);
		vis[u] = x > 0;
	}
	else f[u] = 0, vis[u] = 1;
}

inline void solve()
{
	int n = read(), rt = read(), res = 0, sum = 0;
	for (int i = 1; i <= n; ++i) a[i] = read(), id[i] = i, T[i].clear();
	std::sort(id + 1, id + n + 1, [&](int u, int v) { return a[u] < a[v]; });
	for (int i = 1; i <= n - 1; ++i)
	{
		int u = read(), v = read();
		T[u].push_back(v), T[v].push_back(u);
	}
	dfs(rt, 0);
	for (int i = 1; i <= n; ++i) upd(sum, f[i]);
	inv[0] = inv[1] = 1;
	for (int i = 2; i <= n; ++i) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
	for (int i = 1; i <= n; ++i)
	{
		upd(res, 1LL * sum * (a[id[i]] - a[id[i - 1]]) % mod);
		int u = id[i];
		ban[u] = 1, f[u] = 0;
		DFS(rt, 0);
		sum = 0;
		for (int i = 1; i <= n; ++i) upd(sum, f[i]);
		// int u = id[i];
		// // upd(sum, mod - f[u]);
		// std::vector<int> vec;
		// for (int v = u; v && !ban[v]; v = par[v])
		// 	vec.push_back(v), upd(sum, mod - f[v]);
		// for (int i = (int)vec.size() - 1; i >= 1; --i)
		// {
		// 	int fa = vec[i], u = vec[i - 1];
		// 	upd(f[fa], mod - 1);
		// 	upd(f[fa], mod - 1LL * f[u] * inv[p[fa] - vis[u]] % mod);
		// 	if (vis[u]) f[fa] = 2LL * f[fa] % mod;
		// }
		// // for (int i = 1; i <= n; ++i) printf("%d ", f[i]); puts("");
		// f[u] = 0, ban[u] = 1;
		// for (int v = u; v && !vis[v]; v = par[v]) ++p[v], vis[v] = 1;
		// for (int i = 1; i < vec.size(); ++i)
		// {
		// 	int fa = vec[i], u = vec[i - 1];
		// 	f[fa] = 1LL * f[fa] * inv[1] % mod;
		// 	upd(f[fa], 1LL * f[u] * inv[p[fa] - vis[u]] % mod);
		// 	upd(f[fa], 1);
		// 	upd(sum, f[fa]);
		// }
		// for (int i = 1; i <= n; ++i) printf("%d ", f[i]); puts("");
	}
	printf("%d\n", res);
}

int main()
{
	freopen("dfs.in", "r", stdin), freopen("dfs.out", "w", stdout);
	for (int T = read(); T; --T) solve();
	return 0;
}