/** * - Meet Brahmbhatt * - Hard work always pays off **/ #include"bits/stdc++.h" using namespace std; #ifdef MeetBrahmbhatt #include "debug.h" #else #define dbg(...) 72 #endif #define endl "\n" #define int long long const long long INF = 4e18; class DSU { public : vector parent; vector size; set USED; int comps; DSU(int n) : parent(n), size(n), comps(n) { for (int i = 0; i < n; i++) { parent[i] = i; size[i] = 1; } } int find(int a) { if (parent[a] == a) return a; return parent[a] = find(parent[a]); } bool join(int x, int y) { USED.insert(x); USED.insert(y); int a = find(x); int b = find(y); if (a != b) { if (size[a] < size[b]) swap(a, b); parent[b] = a; size[a] += size[b]; comps -= 1; return true; } return false; } void reset() { comps = (int) parent.size(); for (int i : USED) { parent[i] = i; size[i] = 1; } USED.clear(); } bool same(int x, int y) { return find(x) == find(y); } int Components() { return comps; } }; void solve() { int n, q; cin >> n >> q; constexpr int MOD = 998244353; vector P(n + 1, 1); for (int i = 1; i <= n; i++) { P[i] = (P[i - 1] * 2) % MOD; } DSU D(2 * n); while (q--) { int t; cin >> t; if (t == 1) { int u, v; cin >> u >> v; --u; --v; if (D.same(u, v + n)) { cout << 0 << endl; } else if (!D.same(u, v)) { D.join(u, v); D.join(u + n, v + n); assert(D.Components() % 2 == 0); cout << P[D.Components() / 2] << endl; } } else if (t == 2) { int u, v; cin >> u >> v; --u; --v; if (D.same(u, v)) { cout << 0 << endl; } else if (!D.same(u, v + n)) { D.join(u, v + n); D.join(v, u + n); assert(D.Components() % 2 == 0); cout << P[D.Components() / 2] << endl; } } else { D.reset(); cout << P[n] << endl; } } } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(9); int tt = 1; // cin >> tt; while (tt--) solve(); return 0; }