n=int(input()) N=2**n d=[0]*n d[-1]=1 m=998244353 for i in range(n): b=0 k,*c=map(int,input().split()) for x in c: b+=1<<(c-1) for i in range(N-1,-1,-1): d[i&b]+=d[i] d[i&b]%=m print(d[0])