#include using namespace std; int main() { int N; cin >> N; int dp[1<<13][N]; int A[N]; int mod = 998244353; for( int S = (1<<13)-1; S >= 0; S-- ) { for( int i = 0; i < N-1; i++ ) { dp[S][i] = 0; A[i] = 0; } } for( int i = 0; i < N; i++ ) { int k; cin >> k; for( int j = 0; j < k; j++ ) { int c; cin >> c; A[i] |= 1<<(c-1); } dp[A[i]][i]++; } for( int S = (1<<13)-1; S >= 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; ans = 0; for( int i = 0; i < N; i++ ) { ans += dp[0][i]; ans %= mod; } cout << ans << endl; }