#include using namespace std; struct Problem_E { int n, num_component; bool is_zero; stack st; vector weight, parent_or_size; Problem_E(int _n) : n(_n), num_component(_n), weight(n), parent_or_size(n, -1), is_zero(false) {} int leader(int v){ if(parent_or_size[v] < 0) return v; int root = leader(parent_or_size[v]); weight[v] ^= weight[parent_or_size[v]]; return parent_or_size[v] = root; } void merge(int u, int v, int w){ int x = leader(u), y = leader(v); w ^= weight[u] ^ weight[v]; if(x == y){ if(w)is_zero = true; return; } 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; weight[y] = w; num_component--; st.push(x), st.push(y); } void reset(){ is_zero = false; num_component = n; while(!st.empty()){ parent_or_size[st.top()] = -1; weight[st.top()] = 0; st.pop(); } } }; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, Q, cmd, u, v;; cin >> N >> Q; vector pow2(N + 1); pow2[0] = 1; for(int i = 0; i < N; i++) { pow2[i + 1] = pow2[i] + pow2[i]; if(pow2[i + 1] >= 998244353) pow2[i + 1] -= 998244353; } Problem_E uf(N); while(Q--){ cin >> cmd; if(cmd <= 2){ cin >> u >> v; uf.merge(--u, --v, --cmd); }else{ uf.reset(); } cout << (uf.is_zero ? 0 : pow2[uf.num_component]) << '\n'; } }