#include #include using namespace std; using mint = atcoder::modint998244353; struct Problem_E{ int num_component, _n; vector parent_or_size; stack stk; Problem_E(int N) : _n(N), num_component(N), parent_or_size(N, -1) {} int leader(int v){ if(parent_or_size[v] < 0) return v; return parent_or_size[v] = leader(parent_or_size[v]); } bool same(int u, int v) { return leader(u) == leader(v); } void merge(int u, int v){ int x = leader(u), y = leader(v); if(x == y) return; if(-parent_or_size[x] < parent_or_size[y]) swap(x, y); stk.push(x), stk.push(y); parent_or_size[x] += parent_or_size[y]; parent_or_size[y] = x; num_component--; } void reset(){ num_component = _n; while(!stk.empty()) { parent_or_size[stk.top()] = -1; stk.pop(); } } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q; cin >> N >> Q; vector pow2(N + 1); pow2[0] = 1; for(int i = 0; i < N; i++) pow2[i + 1] = pow2[i] + pow2[i]; Problem_E uf(2 * N); bool is_zero = false; int type, u, v; while(Q--){ cin >> type; if(type <= 2){ cin >> u >> v; u--, v--; if(type == 1) { uf.merge(u, v); uf.merge(u + N, v + N); } else { uf.merge(u, v + N); uf.merge(u + N, v); } if(uf.same(u, u + N)) is_zero = true; } else { is_zero = false; uf.reset(); } cout << (is_zero ? 0 : pow2[uf.num_component >> 1].val()) << '\n'; } }