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): rx = self.find(x) ry = self.find(y) c = self.diff_weight[y]^self.diff_weight[x] if rx != ry: if self.rank[rx] < self.rank[ry]: rx, ry = ry, rx if self.rank[rx] == self.rank[ry]: self.rank[rx] += 1 self.par[ry] = rx self.size[rx] += self.size[ry] self.diff_weight[ry] = w^c 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 stack = set() if flag: print(ans) else: print(0)