import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[][] dp = new int[1<<13][N]; int[] A = new int[N]; int mod = 998244353; for( int i = 0; i < N; i++ ) { int k = sc.nextInt(); for( int j = 0; j < k; j++ ) { int c = sc.nextInt()-1; A[i] |= 1<= 0 ; S-- ) { for( int i = 0; i < N-1; i++ ) { for( int j = i+1; j < N; j++ ) { dp[S&A[j]][j] += dp[S][i]; dp[S&A[j]][j] %= mod; } } } int ans = 0; for( int i = 0; i < N; i++ ) { ans += dp[0][i]; ans %= mod; } System.out.println(ans); } }