import sys,random,bisect from collections import deque,defaultdict from heapq import heapify,heappop,heappush from itertools import permutations from math import gcd,log input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) class UnionFindVerSize(): def __init__(self, N): self._parent = [n for n in range(0, N)] self._size = [1] * N self.group = N def find_root(self, x): if self._parent[x] == x: return x self._parent[x] = self.find_root(self._parent[x]) return self._parent[x] def unite(self, x, y): gx = self.find_root(x) gy = self.find_root(y) if gx == gy: return self.group -= 1 if self._size[gx] < self._size[gy]: self._parent[gx] = gy self._size[gy] += self._size[gx] else: self._parent[gy] = gx self._size[gx] += self._size[gy] def get_size(self, x): return self._size[self.find_root(x)] def is_same_group(self, x, y): return self.find_root(x) == self.find_root(y) N,Q = mi() parent = [(i,-1) for i in range(N)] sz = [1] * N contradict = False free = N parent_change = [] sz_change = [] contradict_change = [] free_change = [] def calc_val(v): res = 0 while parent[v][1]!=-1: res ^= parent[v][1] v = parent[v][0] return res def find_root(v): while parent[v][1]!=-1: v = parent[v][0] return v def add_query(t,u,v,p): global contradict,free pu,pv = find_root(u),find_root(v) cu,cv = calc_val(u),calc_val(v) if pu == pv: if cu!=cv^p: contradict_change.append((t,contradict,True)) contradict = True return u,v = pu,pv p = cu^cv^p if sz[u] > sz[v]: u,v = v,u parent_change.append((t,u,parent[u],(v,p))) parent[u] = (v,p) sz_change.append((t,v,sz[v],sz[v]+sz[u])) sz[v] += sz[u] free_change.append((t,free,free-1)) free -= 1 def undo_query(t): global contradict,free while parent_change and parent_change[-1][0] == t: _,v,pre,now = parent_change.pop() parent[v] = pre while sz_change and sz_change[-1][0] == t: _,v,pre,now = sz_change.pop() sz[v] = pre while contradict_change and contradict_change[-1][0] == t: _,pre,now = contradict_change.pop() contradict = pre while free_change and free_change[-1][0] == t: _,pre,now = free_change.pop() free = pre time_stack = [] for tim in range(Q): t,*query = mi() if t == 1: u,v = query u,v = u-1,v-1 if u!=v: add_query(tim,u,v,1) time_stack.append(tim) elif t == 2: u,v = query u,v = u-1,v-1 if u!=v: add_query(tim,u,v,0) time_stack.append(tim) else: while time_stack: undo_query(time_stack.pop()) #print(parent) if contradict: print(0) else: print(pow(2,free,998244353))