mod = 998244353 eps = 10**-9 def main(): import sys input = sys.stdin.readline N = int(input()) C = [] for _ in range(N): line = list(map(int, input().split())) state = 0 for c in line[1:]: state += 1 << (c - 1) C.append(state) dp = [0] * (1 << 12) dp[-1] = 1 for c in C: dp_new = [0] * (1 << 12) for state in range(1 << 12): state_new = state & c dp_new[state] = (dp_new[state] + dp[state])%mod dp_new[state_new] = (dp_new[state_new] + dp[state])%mod dp = dp_new print(dp[0]) if __name__ == '__main__': main()