class UF: def __init__(self,n): self.p = {} def f(self,x): if x not in self.p: self.p[x] = -1; return x elif self.p[x]<0: return x else: self.p[x] = self.f(self.p[x]); return self.p[x] def u(self,x,y): x = self.f(x); y = self.f(y) if x==y: return if -self.p[x]<-self.p[y]: x,y = y,x self.p[x] += self.p[y]; self.p[y] = x def s(self,x,y): return self.f(x) == self.f(y) n,q = map(int,input().split()) mod = 998244353; uf = UF(2*n); c = n for _ in range(q): t,*uv = map(int,input().split()) if t==1: u,v = [w-1 for w in uv] if uf.s(u,v+n): c = -1 elif not uf.s(u,v): uf.u(u,v); uf.u(u+n,v+n); c -= 1 if t==2: u,v = [w-1 for w in uv] if uf.s(u,v): c = -1 elif not uf.s(u,v+n): uf.u(u,v+n); uf.u(u+n,v); c -= 1 if t==3: uf = UF(2*n); c = n print(pow(2,c,mod) if c>=0 else 0)