#include using namespace std; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; //2のべき乗を求める vector pow2(N + 1); pow2[0] = 1; for(int i = 0; i < N; i++){ pow2[i + 1] = pow2[i] << 1; if(pow2[i + 1] >= 998244353) pow2[i + 1] -= 998244353; } //Union Find bool is_zero = false; //0通りか否か int num_component = 2 * N; //連結成分の数 vector parent_or_size(2 * N, -1); //連結成分のサイズ_or_親の頂点 stack st; //頂点初期化用スタック function leader = [&](int v){ //連結成分の代表元の頂点を収得しながら経路圧縮 if(parent_or_size[v] < 0) return v; return parent_or_size[v] = leader(parent_or_size[v]); }; auto merge = [&](int u, int v){ //頂点uと頂点vを重みwの辺でマージ int x = leader(u), y = leader(v); if(x == y) return; num_component--; st.push(x), st.push(y); if(-parent_or_size[x] < -parent_or_size[y]) swap(x, y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; }; auto reset = [&](){ //初期化 is_zero = false; num_component = 2 * N; while(!st.empty()){ parent_or_size[st.top()] = -1; st.pop(); } }; int type, u, v; while(Q--){ cin >> type; if(type <= 2){ cin >> u >> v; u--, v--; if(type == 1){ merge(u, v); merge(u + N, v + N); }else{ merge(u, v + N); merge(u + N, v); } if(leader(u) == leader(u + N)) is_zero = true; }else{ reset(); } cout << (is_zero ? 0 : pow2[num_component >> 1]) << endl; } }