#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int N,M; vector G[202020]; int A[202020]; ll mod = 998244353; int main() { cin >> N >> M; for(int i = 1; i <= N; ++i) cin >> A[i]; for(int i = 0; i < M; ++i) { int u,v; cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } ll ans = 1; vector vis(N+1); vector S(N+1); for(int i = 1; i <= N; ++i) { if(vis[i]) continue; ll sum = 0; vis[i] = true; queue q; vector route; q.push(i); route.push_back(i); while(!q.empty()) { int v = q.front(); q.pop(); sum += A[v]; sum %= mod; for(int ne : G[v]) { if(vis[ne]) continue; vis[ne] = true; q.push(ne); route.push_back(ne); } } for(int v : route) S[v] = sum; } for(int i = 1; i <= N; ++i) { ans *= S[i]; ans %= mod; } cout << ans << endl; }