#include using namespace std; const long long MOD = 998244353; const long long HALF = 499122177; struct unionfind{ vector p; vector id; unionfind(int N){ p = vector(N, -1); } int root(int x){ if (p[x] < 0){ return x; } else { p[x] = root(p[x]); return p[x]; } } bool same(int x, int y){ return root(x) == root(y); } void unite(int x, int y){ id.push_back(x); id.push_back(y); x = root(x); y = root(y); if (x != y){ if (p[x] < p[y]){ swap(x, y); } p[y] += p[x]; p[x] = y; } } void reset(){ for (int v : id){ p[v] = -1; } id.clear(); } }; int main(){ int N, Q; cin >> N >> Q; long long a = 1; for (int i = 0; i < N; i++){ a *= 2; a %= MOD; } unionfind UF(N * 2); long long ans = a; for (int i = 0; i < Q; i++){ int t; cin >> t; if (t == 1){ int u, v; cin >> u >> v; u--; v--; if (UF.same(u, N + v)){ ans = 0; } else if (!UF.same(u, v)){ ans *= HALF; ans %= MOD; UF.unite(u, v); UF.unite(N + u, N + v); } } if (t == 2){ int u, v; cin >> u >> v; u--; v--; if (UF.same(u, v)){ ans = 0; } else if (!UF.same(u, N + v)){ ans *= HALF; ans %= MOD; UF.unite(u, N + v); UF.unite(N + u, v); } } if (t == 3){ ans = a; UF.reset(); } cout << ans << endl; } }