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
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 300005, M = 998244353;
int n, m, k;
vector<int> a[N];
bool c[N];
int yl[N];
vector<pair<int, int> > t[N];
map<int, int> mp;
vector<int> v;
bool f;
void dfs(int x, int l) {
  if (c[x]) {
    if (l != yl[x]) f = false;
    return;
  }
  c[x] = true;
  yl[x] = l;
  v.push_back(x);
  for (int i = 0; i < ((int)(a[x]).size()); ++i) {
    if (mp.find(l + i) == mp.end())
      mp[l + i] = a[x][i];
    else if (mp[l + i] != a[x][i])
      f = false;
  }
  for (int i = 0; i < ((int)(a[x]).size()); ++i) {
    while (!t[a[x][i]].empty()) {
      pair<int, int> h = t[a[x][i]].back();
      t[a[x][i]].pop_back();
      dfs(h.first, l + i - h.second);
    }
  }
}
int b[N];
int dp[N];
void solv() {
  cin >> n >> m >> k;
  for (int i = 1; i <= n; ++i) {
    int q;
    cin >> q;
    while (q--) {
      int x;
      cin >> x;
      a[i].push_back(x);
    }
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < ((int)(a[i]).size()); ++j) {
      if (c[a[i][j]]) {
        cout << "0\n";
        return;
      }
      c[a[i][j]] = true;
    }
    for (int j = 0; j < ((int)(a[i]).size()); ++j) c[a[i][j]] = false;
  }
  for (int i = 1; i <= n; ++i) {
    if (((int)(a[i]).size()) == 1) continue;
    for (int j = 0; j < ((int)(a[i]).size()); ++j)
      t[a[i][j]].push_back(make_pair(i, j));
  }
  int ak = 0;
  for (int i = 1; i <= k; ++i) {
    if (t[i].empty()) ++ak;
  }
  for (int i = 1; i <= n; ++i) {
    if (((int)(a[i]).size()) == 1) continue;
    if (!c[i]) {
      mp.clear();
      v.clear();
      f = true;
      dfs(i, 0);
      if (f) {
        b[((int)(mp).size())]++;
      }
    }
  }
  vector<int> db;
  for (int i = 1; i <= m; ++i) {
    if (b[i]) db.push_back(i);
  }
  dp[0] = 1;
  for (int i = 1; i <= m; ++i) {
    dp[i] = (dp[i - 1] * 1LL * ak) % M;
    for (int j = 0; j < ((int)(db).size()); ++j) {
      if (i - db[j] >= 0) dp[i] = (dp[i] + dp[i - db[j]] * 1LL * b[db[j]]) % M;
    }
  }
  cout << dp[m] << "\n";
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0);
  int tt = 1;
  while (tt--) solv();
  return 0;
}
