import sys,random input = lambda :sys.stdin.readline().rstrip() mi = lambda :map(int,input().split()) li = lambda :list(mi()) mod = 998244353 N = int(input()) dp = [0 for i in range(4096)] dp[4095] = 1 for i in range(N): k,*C = li() tmp = 0 for c in C: tmp += pow(2,c-1) assert len(C)==k ndp = [dp[j] for j in range(4096)] for j in range(4096): ndp[j&tmp] += dp[j] ndp[j] %= mod dp = ndp print(dp[0] % mod)