using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static int[] NList => ReadLine().Split().Select(int.Parse).ToArray(); static int[][] NArr(long n) => Enumerable.Repeat(0, (int)n).Select(_ => NList).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, q) = (c[0], c[1]); var map = NArr(q); var mlist = new List(); var ans = new List(); var all = Exp(2, n, mod); foreach (var li in map) { if (li[0] == 3) { ans.AddRange(Sub(n, mlist, all)); ans.Add(all); mlist = new List(); } else mlist.Add(li); } ans.AddRange(Sub(n, mlist, all)); WriteLine(string.Join("\n", ans)); } static long Exp(long n, long p, int mod) { long _n = n % mod; var _p = p; var result = 1L; if ((_p & 1) == 1) result *= _n; while (_p > 0) { _n = _n * _n % mod; _p >>= 1; if ((_p & 1) == 1) result = result * _n % mod; } return result; } static int mod = 998_244_353; static int half = 499_122_177; static List Sub(int n, List map, long all) { if (map.Count == 0) return new List(); var set = new HashSet(); foreach (var li in map) { set.Add(li[1]); set.Add(li[2]); } var list = new List(set); list.Sort(); var dic = new Dictionary(); for (var i = 0; i < list.Count; ++i) dic[list[i]] = i; var zeros = new HashSet[list.Count]; var ones = new HashSet[list.Count]; for (var i = 0; i < list.Count; ++i) { zeros[i] = new HashSet{ i }; ones[i] = new HashSet(); } var uf = new UnionFindTree(list.Count); var ans = new List(map.Count); var tmp = all; foreach (var li in map) { var a = dic[li[1]]; var b = dic[li[2]]; if (uf.IsSameTree(a, b)) { var r = uf.GetRoot(a); if (li[0] == 1) { if (zeros[r].Contains(a) != zeros[r].Contains(b)) tmp = 0; } else { if (zeros[r].Contains(b) == zeros[r].Contains(a)) tmp = 0; } } else { var asize = uf.GetSize(a); var bsize = uf.GetSize(b); uf.Unite(a, b); var nr = uf.GetRoot(a); var v = asize > bsize ? a : b; if (li[0] == 1) { foreach (var zi in zeros[v ^ a ^ b]) zeros[v].Add(zi); foreach (var oi in ones[v ^ a ^ b]) ones[v].Add(oi); } else { foreach (var zi in zeros[v ^ a ^ b]) ones[v].Add(zi); foreach (var oi in ones[v ^ a ^ b]) zeros[v].Add(oi); } zeros[nr] = zeros[v]; ones[nr] = ones[v]; tmp = tmp * half % mod; } ans.Add(tmp); } return ans; } class UnionFindTree { int[] roots; public UnionFindTree(int size) { roots = new int[size]; for (var i = 0; i < size; ++i) roots[i] = -1; } public int GetRoot(int a) { if (roots[a] < 0) return a; return roots[a] = GetRoot(roots[a]); } public bool IsSameTree(int a, int b) { return GetRoot(a) == GetRoot(b); } public bool Unite(int a, int b) { var x = GetRoot(a); var y = GetRoot(b); if (x == y) return false; if (-roots[x] < -roots[y]) { var tmp = x; x = y; y = tmp; } roots[x] += roots[y]; roots[y] = x; return true; } public int GetSize(int a) { return -roots[GetRoot(a)]; } } }