#include <bits/stdc++.h>
using namespace std;
const int maxn = 300005, mod = 998244353;
int n, m, k, mx;
int in[maxn], out[maxn], f[maxn], tot[maxn], q[maxn], tmp[maxn];
vector<int> t, v[maxn], g[maxn];
map<int, int> mp[maxn];
void dfs(int x, int d) {
  if (in[x] > 1 || out[x] > 1) return;
  if (out[x] == 0) tot[d]++, mx = max(mx, d);
  for (int i = 0; i < g[x].size(); i++) dfs(g[x][i], d + 1);
}
int main() {
  scanf("%d%d%d", &n, &m, &k);
  for (int i = 1, c; i <= n; i++) {
    scanf("%d", &c), v[i].resize(c);
    for (int j = 0; j < c; j++) {
      scanf("%d", &v[i][j]);
      if (j > 0 && mp[v[i][j - 1]][v[i][j]] == 0)
        mp[v[i][j - 1]][v[i][j]] = 1, g[v[i][j - 1]].push_back(v[i][j]),
                    out[v[i][j - 1]]++, in[v[i][j]]++;
    }
  }
  for (int i = 1; i <= k; i++)
    if (in[i] == 0) dfs(i, 1);
  f[0] = 1;
  for (int i = 1; i <= mx; i++)
    if (tot[i]) t.push_back(i);
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < t.size(); j++)
      if (i >= t[j]) f[i] = (f[i] + 1ll * f[i - t[j]] * tot[t[j]]) % mod;
  printf("%d\n", f[m]);
  return 0;
}
