#include <cstdio>
#include <vector>

typedef long long ll;
const int N = 4e5 + 10;
const int MOD = 998244353;

int a[N];
std::vector<int> e[N];

void solve() {
	int n, root;
	scanf("%d%d", &n, &root);
	for (int i = 1; i <= n; ++i) {
		e[i].clear();
		scanf("%d", a + i);
	}
	for (int i = 1; i < n; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		e[u].push_back(v);
		e[v].push_back(u);
	}
	if (e[root].size() == n - 1) {
		ll ans = 0;
		for (int i = 1; i <= n; ++i) {
			ans += a[root] < a[i] ? a[root] : a[i];
		}
		printf("%lld\n", ans % MOD);
		return;
	}
	return;
}
int main() {
	freopen("dfs.in", "r", stdin);
	freopen("dfs.out", "w", stdout);

	int T;
	scanf("%d", &T);
	while (T--) solve();
	return 0;
}