from sys import stdin n, *indata = map(int, stdin.read().split()) p = 998244353 setlist = [0 for i in range(n)] offset = 0 for i in range(n): k = indata[offset] offset += 1 for j in range(k): setlist[i] += 1 << (indata[offset+j]-1) offset += k dp = [[0 for i in range(1<<12)] for j in range(n+1)] dp[0][(1<<12)-1] = 1 for i in range(n): for j in range(1<<12): dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % p dp[i+1][(j & setlist[i])] = (dp[i+1][(j & setlist[i])] + dp[i][j]) % p print("{}".format(dp[n][0]))