class DisjointSetUnion(): def __init__(self, n): self.n = n self.par_or_size = [-1] * n def merge(self, a, b): assert(0 <= a < self.n) assert(0 <= b < self.n) la = self.leader(a) lb = self.leader(b) if la == lb: return la if -self.par_or_size[la] < -self.par_or_size[lb]: la, lb = lb, la self.par_or_size[la] += self.par_or_size[lb] self.par_or_size[lb] = la return la def same(self, a, b): assert(0 <= a < self.n) assert(0 <= b < self.n) return self.leader(a) == self.leader(b) def leader(self, a): assert(0 <= a < self.n) if (self.par_or_size[a] < 0): return a else: self.par_or_size[a] = self.leader(self.par_or_size[a]) return self.par_or_size[a] def size(self, a): assert(0 <= a < self.n) return - self.par_or_size[self.leader(a)] def group(self): result = dict() for a in range(self.n): la = self.leader(a) if la not in result: result[la] = [] result[la].append(a) return result MOD = 998244353 N, Q = map(int, input().split()) cnt = 2 * N valid = 1 dsu = DisjointSetUnion(2 * N) done = set() for _ in range(Q): query = list(map(int, input().split())) if query[0] == 2: u, v = query[1] - 1, query[2] - 1 if u != v: done.add(u) done.add(v) if not dsu.same(u, v + N): cnt -= 1 if not dsu.same(v, u + N): cnt -= 1 dsu.merge(u, v + N) dsu.merge(v, u + N) if dsu.same(u, u + N) or dsu.same(v, v + N): valid = 0 else: valid = 0 elif query[0] == 1: u, v = query[1] - 1, query[2] - 1 if u != v: done.add(u) done.add(v) if not dsu.same(u, v): cnt -= 1 if not dsu.same(u + N, v + N): cnt -= 1 dsu.merge(u, v) dsu.merge(u + N, v + N) if dsu.same(u, u + N) or dsu.same(v, v + N): valid = 0 else: pass else: cnt = 2 * N for i in done: dsu.par_or_size[i] = -1 dsu.par_or_size[i + N] = -1 valid = 1 if valid: print(pow(2, cnt // 2, MOD)) else: print(0)