#include <bits/stdc++.h>
#define rep(x, l, r) for(int x = l; x <= r; x++)
using namespace std;

const int mod = 998244353;
int a[800005];

int fast_power(int a, int b){
	int x;
	for(x = 1; b; b >>= 1){
		if(b & 1) x = 1ll * x * a % mod;
		a = 1ll * a * a % mod;
	}
	return x;
}

int main(){
	freopen("dfs.in", "r", stdin);
	freopen("dfs.out", "w", stdout);
	int T;
	scanf("%d", &T);
	while(T--){
		int n, root;
		scanf("%d%d", &n, &root);
		int ans = 0;
		rep(i, 1, n){
			scanf("%d", &a[i]);
			ans = (ans + a[i]) % mod;
		}
		rep(i, 1, n){
			if(i != root) ans = (ans + 1ll * (a[root] + a[i]) * fast_power(n - 1, mod - 2) % mod) % mod;
		}
		rep(i, 1, n - 1){
			int x;
			scanf("%d%d", &x, &x);
		}
		printf("%d\n", ans);
	}
	return 0;
}
