#include #include using namespace std; using namespace atcoder; using ll = long long; using ld = long double; using mint = modint998244353; int N, M; ll A[202020]; vector G[202020]; int main() { cin >> N >> M; for (int i = 0; i < N; i++) cin >> A[i]; dsu uf(N); for (int i = 0; i < M; i++) { int u, v; cin >> u >> v; u--, v--; uf.merge(u, v); } mint ans = 1; for (auto s: uf.groups()) { mint sum = 0; for (auto x: s) { sum += A[x]; } ans *= sum.pow(s.size()); } cout << ans.val() << endl; return 0; }