#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
const int LOG2 = 18;
const int MOD = 998244353;
const long long oo = 1e18;
set<int> g[N];
vector<int> g2[N];
int in[N], seen[N], sz, bad[N], val[N];
void mark_bad(int u) {
  bad[u] = 1;
  for (int v : g2[u])
    if (!bad[v]) mark_bad(v);
}
int go(int u) {
  int ok = 1;
  sz++;
  seen[u] = 1;
  ok &= g[u].size() <= 1;
  for (int v : g[u]) {
    if (!seen[v])
      ok &= go(v);
    else
      ok = 0;
  }
  return ok;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  for (int it = 0; it < n; it++) {
    int len;
    cin >> len;
    int last = -1;
    while (len--) {
      int x;
      cin >> x;
      if (last != -1) {
        in[x]++;
        g[last].insert(x);
        g2[last].push_back(x);
        g2[x].push_back(last);
      }
      last = x;
    }
  }
  map<int, int> by_sz;
  for (int i = 1; i <= k; i++) {
    if (in[i] == 0 && !bad[i]) {
      sz = 0;
      if (!go(i)) mark_bad(i);
      val[i] = sz;
    }
  }
  for (int i = 1; i <= k; i++) {
    if (!seen[i]) {
      if (!go(i)) mark_bad(i);
    }
  }
  for (int i = 1; i <= k; i++) {
    if (in[i] == 0 && !bad[i]) {
      by_sz[val[i]]++;
    }
  }
  vector<int> dp(2 * N + 2);
  dp[m] = 1;
  for (int i = m - 1; i >= 0; i--) {
    for (auto e : by_sz) {
      dp[i] += 1ll * dp[i + e.first] * e.second % MOD;
      if (dp[i] >= MOD) dp[i] -= MOD;
    }
  }
  cout << dp[0] << '\n';
}
