import java.util.*; import java.io.*; public class Main { static final int MOD = 998244353; public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); TreeMap current = new TreeMap<>(); current.put((1 << 12) - 1, 1); for (int i = 0; i < n; i++) { int count = sc.nextInt(); int x = 0; for (int j = 0; j < count; j++) { x += (1 << (sc.nextInt() - 1)); } Integer key = -1; while ((key = current.higherKey(key)) != null) { int next = (key & x); current.put(next, (current.getOrDefault(next, 0) + current.get(key)) % MOD); } } System.out.println(current.getOrDefault(0, 0)); } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String nextLine() throws Exception { return br.readLine(); } public String next() throws Exception { if (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }