#include <bits/stdc++.h>
using namespace std;
template<typename T>
inline void read(T &x) {
	x = 0;
	char ch = getchar();
	while (!isdigit(ch))
		ch = getchar();
	while (isdigit(ch))
		x = x * 10 + ch - 48, ch = getchar();
}
const int P = 998244353;
inline void add(int &x, int y) {
	(x += y) >= P && (x -= P);
}
inline void sub(int &x, int y) {
	(x -= y) < 0 && (x += P);
}
inline void mul(int &x, int y) {
	x = 1ull * x * y % P;
}
inline int Add(int x, int y) {
	return add(x, y), x;
}
inline int Sub(int x, int y) {
	return sub(x, y), x;
}
inline int Mul(int x, int y) {
	return mul(x, y), x;
}
const int N = 400005;
int n, inv[N], root, a[N], id[N], fa[N], cnt[N];
vector<int> e[N];
bool mark1[N], mark[N];
void dfs1(int u) {
	for (auto v : e[u]) {
		e[v].erase(find(e[v].begin(), e[v].end(), u));
		fa[v] = u;
		dfs1(v);
	}
}
void activate(int u) {
	mark1[u] = true;
	for (; fa[u]; u = fa[u]) {
		if (mark[u]) break;
		mark[u] = true;
		++cnt[fa[u]];
	}
}
int all;
int dfs2(int u) {
	if (mark1[u]) {
		for (auto v : e[u])
			dfs2(v);
		return 0;
	}
	int res = 1;
	for (auto v : e[u]) {
		int cur = dfs2(v);
		mul(cur, inv[cnt[u] - mark[v] + 1]);
		add(res, cur);
	}
	add(all, res);
	return res;
}
void solve() {
	read(n), read(root);
	fa[root] = 0;
	for (int i = 1; i <= n; ++i)
		e[i].clear();
	for (int i = 1; i <= n; ++i)
		read(a[i]);
	for (int i = 1; i < n; ++i) {
		int u, v;
		read(u), read(v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	iota(id + 1, id + n + 1, 1);
	sort(id + 1, id + n + 1, [&](int i, int j) {
		return a[i] < a[j];
	});
	dfs1(root);
	memset(mark, false, n + 1);
	memset(mark1, false, n + 1);
	memset(cnt, false, (n + 1) * 4);
	int ans = 0;
	for (int o = 1; o <= n; ++o) {
		int i = id[o];
		all = 0, dfs2(root);
		add(ans, Mul(a[i] - a[id[o - 1]], all));
		activate(i);
	}
	printf("%d\n", ans);
}
int main() {
	freopen("dfs.in", "r", stdin);
	freopen("dfs.out", "w", stdout);
	inv[0] = inv[1] = 1;
	for (int i = 2; i < N; ++i)
		inv[i] = Mul(P - P / i, inv[P % i]);
	int t;
	read(t);
	while (t--)	
		solve();
	return 0;
}
