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

template <typename T>
inline void read(T &f) {
	f = 0; int fu = 0; char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') fu = 1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		f = f * 10 + (c - '0');
		c = getchar();
	}
	if (fu) f = -f;
}

const int md = 998244353;

inline int add(int x, int y) {
	if (x + y >= md) return x + y - md;
	return x + y;
}

inline int sub(int x, int y) {
	if (x < y) return x - y + md;
	return x - y;
}

inline int mul(int x, int y) { return 1ull * x * y % md; }

inline int fpow(int x, int y) {
	int ans = 1;
	while (y) {
		if (y & 1) ans = mul(ans, x);
		y >>= 1; x = mul(x, x);
	}
	return ans;
}

const int N = 4e5 + 5;

vector <int> adj[N];
int fa[N], now[N], cnt[N], ban[N], bans[N], a[N], id[N], inv[N], sums[N], dep[N];
int T, n, rt, ans, all;

bool cmp(int i, int j) { return a[i] < a[j]; }

void dfs1(int u) {
	sums[u] = 1;
	for (auto v : adj[u]) {
		if (v == fa[u]) continue;
		dep[v] = dep[u] + 1; fa[v] = u; dfs1(v); ++cnt[u];
		sums[u] = add(sums[u], sums[v]);
	}
}

int calc(int u) {
	int sum = 1, cc = 1;
	while (fa[u] && !ban[fa[u]]) {
		u = fa[u];
		cc = mul(cc, now[u]);
		sum = add(sum, cc);
	}
	return sum;
}

void upd(int u) {
	if (ban[u]) return;
	int coef = inv[cnt[u]]; now[u] = sub(now[u], coef);
	int cc = mul(coef, sub(sums[u], 1));
	sums[u] = sub(sums[u], cc);
	all = sub(all, mul(cc, calc(u)));
	while (fa[u] && !ban[fa[u]]) {
		u = fa[u];
		cc = mul(cc, now[u]);
		sums[u] = sub(sums[u], cc);
	}
}

int main() {
	for (int i = 1; i <= 400000; i++) inv[i] = fpow(i, md - 2);
	read(T);
	while (T--) {
		read(n); read(rt); ans = 0;
		for (int i = 1; i <= n; i++) {
			adj[i].clear();
			ban[i] = bans[i] = cnt[i] = 0;
			now[i] = 1;
		}
		for (int i = 1; i <= n; i++) read(a[i]), id[i] = i;
		sort(id + 1, id + n + 1, cmp);
		for (int i = 1; i < n; i++) {
			int u, v;
			read(u); read(v);
			adj[u].push_back(v);
			adj[v].push_back(u);
		}
		fa[rt] = 0; dep[rt] = 1; dfs1(rt); all = 0;
		for (int i = 1; i <= n; i++) all = add(all, dep[i]);
		ans = mul(a[id[1]], all);
		for (int _ = 1; _ < n; _++) {
			int u = id[_];
			all = sub(all, mul(calc(u), sums[u]));
			ban[u] = 1;
			int cc = sums[u], tu = u;
			while (fa[tu] && !ban[fa[tu]]) {
				tu = fa[tu];
				cc = mul(cc, now[tu]);
				sums[tu] = sub(sums[tu], cc);
			}
			while (!bans[u] && u != rt) {
				bans[u] = 1;
				upd(fa[u]); u = fa[u];
			}
//			fprintf(stderr, "all = %d\n", all);
			ans = add(ans, mul(all, a[id[_ + 1]] - a[id[_]]));
		}
		printf("%d\n", ans);
	}
	return 0;
}
