mod = 998244353 n = int(input()) dp = [[0] * (1<<12) for _ in range(2)] dp[0][0] = 1 for i in range(n): n_dp = [[0] * (1<<12) for _ in range(2)] kc = list(map(int,input().split())) bit = 0 for j in range(1,kc[0] + 1): bit += 1 << (kc[j]-1) for j in range(1 << 12): n_dp[0][j] += dp[0][j] n_dp[1][j] += dp[1][j] if j == 0: if bit != 0: n_dp[0][bit] += 1 n_dp[0][bit] %= mod else: n_dp[1][0] += 1 n_dp[1][bit] += dp[1][0] else: if dp[0][j] > 0: if j & bit: n_dp[0][j & bit] += dp[0][j] n_dp[0][j & bit] %= mod else: n_dp[1][j | bit] += dp[0][j] n_dp[1][j | bit] %= mod if dp[1][j] > 0: n_dp[1][j | bit] += dp[1][j] n_dp[1][j | bit] %= mod # print(n_dp[0]) dp = n_dp print(sum(dp[1]) % mod)