description: A subarray of array a from index l to the index r is the array [a_l, a_{l+1}, ..., a_{r}]. The number of occurrences of the array b in the array a is the number of subarrays of a such that they are equal to b.
  
  You are given n arrays A_1, A_2, ..., A_n; the elements of these arrays are integers from 1 to k. You have to build an array a consisting of m integers from 1 to k in such a way that, for every given subarray A_i, the number of occurrences of A_i in the array a is not less than the number of occurrences of each non-empty subarray of A_i in a. Note that if A_i doesn't occur in a, and no subarray of A_i occurs in a, this condition is still met for A_i.
  
  Your task is to calculate the number of different arrays a you can build, and print it modulo 998244353.
  
  Input
  
  The first line contains three integers n, m and k (1 ≤ n, m, k ≤ 3 ⋅ 10^5) — the number of the given arrays, the desired length of the array a, and the upper bound on the values in the arrays.
  
  Then n lines follow. The i-th line represents the array A_i. The first integer in the i-th line is c_i (1 ≤ c_i ≤ m) — the number of elements in A_i; then, c_i integers from 1 to k follow — the elements of the array A_i.
  
  Additional constraint on the input: ∑_{i=1}^n c_i ≤ 3 ⋅ 10^5; i. e., the number of elements in the given arrays in total does not exceed 3 ⋅ 10^5.
  
  Output
  
  Print one integer — the number of different arrays a you can build, taken modulo 998244353.
  
  Examples
  
  Input
  
  
  2 4 3
  2 1 2
  1 3
  
  
  Output
  
  
  5
  
  
  Input
  
  
  2 4 3
  2 1 2
  3 3 2 1
  
  
  Output
  
  
  0
  
  
  Input
  
  
  1 42 1337
  2 13 31
  
  
  Output
  
  
  721234447
solution: #include <bits/stdc++.h>
  using namespace std;
  void dbg_out() { cerr << endl; }
  template <typename Head, typename... Tail>
  void dbg_out(Head H, Tail... T) {
    cerr << ' ' << H;
    dbg_out(T...);
  }
  pair<int, int> operator*(const pair<int, int> &p, const pair<int, int> &x) {
    pair<int, int> np = make_pair(p.first * x.first, p.second * x.second);
    return np;
  }
  pair<long long, long long> operator%(const pair<long long, long long> &p,
                                       const pair<long long, long long> &x) {
    pair<long long, long long> np =
        make_pair(p.first % x.first, p.second % x.second);
    return np;
  }
  pair<long long, long long> operator*(const pair<long long, long long> &p,
                                       const pair<int, int> &x) {
    pair<long long, long long> np =
        make_pair(p.first * x.first, p.second * x.second);
    return np;
  }
  pair<long long, long long> operator*(const pair<long long, long long> &p,
                                       const pair<long long, long long> &x) {
    pair<long long, long long> np =
        make_pair(p.first * x.first, p.second * x.second);
    return np;
  }
  pair<long long, long long> operator+(const pair<long long, long long> &p,
                                       const pair<long long, long long> &x) {
    pair<long long, long long> np =
        make_pair(p.first + x.first, p.second + x.second);
    return np;
  }
  pair<long long, long long> operator-(const pair<long long, long long> &p,
                                       const pair<long long, long long> &x) {
    pair<long long, long long> np =
        make_pair(p.first - x.first, p.second - x.second);
    return np;
  }
  pair<int, int> operator+(const pair<int, int> &p, const pair<int, int> &x) {
    pair<int, int> np = make_pair(p.first + x.first, p.second + x.second);
    return np;
  }
  pair<int, int> operator-(const pair<int, int> &p, const pair<int, int> &x) {
    pair<int, int> np = make_pair(p.first - x.first, p.second - x.second);
    return np;
  }
  vector<int> prime;
  bool sortinrev(const pair<int, int> &a, const pair<int, int> &b) {
    return (a.first > b.first);
  }
  bool sortbysecdesc(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second == b.second) return a.first > b.first;
    return a.second > b.second;
  }
  bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second == b.second) return a.first > b.first;
    return (a.second < b.second);
  }
  long long powerm(long long a, long long k) {
    if (!k) {
      return 1;
    }
    long long b = powerm(a, k / 2);
    b = b * b % 998244353;
    if (k % 2) {
      return a * b % 998244353;
    } else {
      return b;
    }
  }
  long long power(long long a, long long b) {
    if (b == 1) return a;
    if (b == 0) return 1;
    long long m1 = power(a, b / 2);
    if (b % 2) return m1 * m1 * a;
    return m1 * m1;
  }
  void PFactor(int x) {
    prime.clear();
    for (int i = 2; i <= x / i; i++)
      if (x % i == 0) {
        while (x % i == 0) x /= i, prime.push_back(i);
      }
    if (x > 1) prime.push_back(x);
  }
  bool isprime(long long a) {
    if (a <= 1) return false;
    if (a == 2 || a == 3) return true;
    if (a % 2 == 0 || a % 3 == 0) return false;
    for (long long i = 5; i * i <= a; i = i + 6) {
      if (a % i == 0 || a % (i + 2) == 0) return false;
    }
    return true;
  }
  long long read() {
    long long a = 0;
    char b = 1, c;
    do
      if ((c = getchar()) == 45) b = -1;
    while (c < 48 || c > 57);
    do a = (a << 3) + (a << 1) + (c & 15);
    while ((c = getchar()) > 47 && c < 58);
    return a * b;
  }
  void write(long long x, char c) {
    if (x < 0) putchar(45), x = -x;
    char a[20], s = 0;
    do a[++s] = x % 10 | 48;
    while (x /= 10);
    do putchar(a[s]);
    while (--s);
    putchar(c);
  }
  const int LOGN = 20;
  const int N = (1 << LOGN);
  set<long long> g[N];
  long long n = 0, m = 0, k = 0;
  long long a = 0, b = 0, c = 0;
  string str;
  long long d[N] = {0};
  bool ban[N];
  bool vis[N];
  map<long long, long long> tim;
  long long dp[N];
  long long dfs(long long u, long long fa) {
    if (vis[u]) return -1;
    vis[u] = true;
    if (fa != 0 && (long long)(g[u]).size() == 1) return 1;
    if ((long long)(g[u]).size() == 2 || fa == 0) {
      long long v = (*g[u].begin()) == (-fa) ? (*g[u].rbegin()) : (*g[u].begin());
      long long ans = dfs(v, u);
      if (ans == -1)
        return -1;
      else
        return ans + 1;
    }
    return -1;
  }
  signed main() {
    dp[0] = 1;
    cin >> n >> m >> k;
    for (long long i = 1; i <= n; i++) {
      cin >> a;
      cin >> b;
      for (long long i = 2; i <= a; i++) {
        cin >> c;
        g[b].insert(c);
        g[c].insert(-b);
        b = c;
      }
    }
    for (long long i = 1; i <= k; i++) {
      if ((long long)(g[i]).size() == 0) tim[1]++;
      if ((long long)(g[i]).size() != 1 || vis[i]) continue;
      if ((*g[i].begin()) < 0) continue;
      long long ans = dfs(i, 0);
      if (ans != -1) tim[ans]++;
    }
    for (long long i = 1; i <= m; i++) {
      for (auto x : tim) {
        if (i >= x.first) dp[i] += dp[i - x.first] * x.second;
        dp[i] %= 998244353;
      }
    }
    cout << dp[m];
  }
  