import sys input = sys.stdin.readline class UnionFind(object): def __init__(self, n=1): self.par = [i for i in range(n)] self.rank = [0 for _ in range(n)] self.size = [1 for _ in range(n)] self.diff_weight = [0 for _ in range(n)] def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) self.diff_weight[x] ^= self.diff_weight[self.par[x]] return self.par[x] def union(self, x, y, w): x = self.find(x) y = self.find(y) if x != y: if self.rank[x] < self.rank[y]: x, y = y, x if self.rank[x] == self.rank[y]: self.rank[x] += 1 self.par[y] = x self.size[x] += self.size[y] self.diff_weight[y] = w def is_same(self, x, y): return self.find(x) == self.find(y) def get_size(self, x): x = self.find(x) return self.size[x] def diff(self, x, y): return self.diff_weight[y]^self.diff_weight[x] N, Q = map(int, input().split()) flag = 1 mod = 998244353 N2 = pow(2, N, mod) ans = N2 inv = pow(2, mod - 2, mod) U = UnionFind(N) stack = set() for _ in range(Q): query = list(map(int, input().split())) if query[0] == 1: u, v = query[1:] u, v = u - 1, v - 1 stack.add(u) stack.add(v) if U.is_same(u, v): if U.diff(u, v) == 1: flag = 0 else: U.union(u, v, 0) ans *= inv ans %= mod elif query[0] == 2: u, v = query[1:] u, v = u - 1, v - 1 stack.add(u) stack.add(v) if U.is_same(u, v): if U.diff(u, v) == 0: flag = 0 else: U.union(u, v, 1) ans *= inv ans %= mod else: ans = N2 flag = 1 for s in stack: U.diff_weight[s] = 0 U.par[s] = s U.rank[s] = 0 U.size[s] = 1 if flag: print(ans) else: print(0)