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>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")
typedef long long lld;
typedef double lf;
typedef long double llf;
typedef pair<int,int> pii;
typedef pair<lld,lld> pll;
#define For(i,s,a) for(int i = (int)s; i < (int)a; ++i)
#define rpt(s, it) for(auto it = s.begin(); it != s.end(); ++it)
#define brpt(s, it) for(auto it = s.rend(); it != s.rbegin(); --it)
#define sz size()
#define pb push_back
#define eb emplace_back
#define ff first
#define dd second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define make_unique(x) (x).erase( unique(all(x)), (x).end())
#define popcnt(x) __builtin_popcount(x)
 
template<typename Ta, typename Tb>
ostream & operator <<(ostream & os, pair<Ta, Tb> x){
	return os << x.ff << " " << x.dd;
}

const int N = 6e5 + 1;
const lld mod = 998244353;
int link[N], revlink[N], ile[N];
bitset<N>banned, used, odw;
lld dp[N];
pii ct[N];

void upd(int g, int h) {
	if((link[g] != h && link[g]) || (revlink[h] != g && revlink[h])) {
		banned[g] = banned[h] = 1;
		if(link[g])
			banned[link[g]] = 1;
		if(revlink[g])
			banned[revlink[g]] = 1;
		if(link[h])
			banned[link[h]] = 1;
		if(revlink[h])
			banned[revlink[h]] = 1;
	}
	link[g] = h;
	revlink[h] = g;
}

int dfs(int x, bool ban = 0) {
	ban |= banned[x];
	odw[x] = 1;
	int wyn = 1;
	//cout<<x<<" "<<ban<<" "<<wyn<<endl;
	int cand = 0;
	if(!odw[link[x]] && link[x]) {
		cand = dfs(link[x], ban);
		if(cand >= 0)
			wyn = max(wyn, 1 + dfs(link[x], ban));
		else
			ban = 1, wyn = -696969696;
	}
	if((link[x] && banned[link[x]]) || (revlink[x] && banned[revlink[x]]) || banned[x])
		wyn = -696969696;
	//cout<<x<<" out "<<ban<<" "<<wyn<<endl;
	return wyn;
}

int stos[N], _end;

void solve(void) {
	int n, destlen, k;
	scanf("%d%d%d", &n, &destlen, &k);
	++k;
	For(i, 0, n) {
		int a;
		scanf("%d", &a);
		int lst = -1;
		_end = 0;
		For(j, 0, a) {
			int g;
			scanf("%d", &g);
			stos[++_end] = g;
			used[g] = 1;
			if(lst != -1)
				upd(lst, g);
			lst = g;
		}
		
		sort(stos + 1, stos + 1 + _end);
		For(i, 1, _end - 1)
			if(stos[i] == stos[i + 1]) {
				For(j, 1, _end)
					banned[stos[j]] = 1;
				break;
			}
	}
	
	For(i, 1, k)
		if(!odw[i] && revlink[i] == 0) {
			int tmpxd = dfs(i);//ile[dfs(i)];
	//		cout<<i<<" got "<<tmpxd<<endl;
			if(tmpxd > 0)
				++ile[tmpxd];
		}
	
	/*For(i, 1, k) {
		if(!odw[i])
			banned[i] = 1;
		if(!odw[i] && !used[i])
			++ile[1];
	}*/
	
	int ctct = 0;
	For(i, 1, k)
		if(ile[i]) 
			ct[ctct++] = {i, ile[i]};
		
	
	dp[0] = 1;
	For(i, 1, destlen + 1) {
		For(j, 0, ctct) {
			if(i - ct[j].ff < 0)
				break;
			(dp[i] += dp[i - ct[j].ff] * ct[j].dd) %= mod;
		}
	}

	printf("%lld\n", dp[destlen]);
}
/*
abcdef
    efgh
   defghijklmnopqrst
*/

int32_t main(void){
	int tt = 1;
	//scanf("%d", &tt);
	while(tt--) 
		solve();
}

/*
19 5 88
2 7 78
3 78 28 76
4 28 40 83 59
4 17 12 76 75

5 35 75 62 54 4
5 19 24 67 87 4
3 19 48 81
5 52 67 53 62 53
4 4 56 55 7
5 4 55 56 28 77
5 30 81 28 37 79
5 79 51 17 82 2
4 13 88 73 82
2 53 71

4 22 46 68 10
3 87 11 75
2 29 10
2 74 50
4 63 15 59 72
*/

/*
30 2 76

2 48 1
2 1 67
2 67 22
2 1 30

2 12 12
2 62 12
2 8 12
2 8 9
2 37 9
2 48 8

2 17 47
2 28 15
2 47 15
2 15 72
 
2 44 61
2 76 61
2 61 68
2 68 21

2 6 53
2 53 20
2 29 20

2 66 13
2 40 7
2 57 25
2 41 52

2 72 4
2 58 32
2 65 40
2 50 68
2 24 56

*/

/*
11 3 52
2 18 9
3 36 12 35
1 38
1 43
3 20 32 24
3 21 7 37
2 12 36
1 50
3 11 26 17
3 29 11 29
2 47 38

11 3 52
2 18 9
X 3 36 12 35
A 1 38
1 43
3 20 32 24
3 21 7 37
X 2 12 36
1 50
3 11 26 17
3 29 11 29
2 47 38

*/

/*
3 50 20
6 1 2 3 4 5 6
4         5 6 7 8
10      4 5 6 7 8 9 10 12 13 14
*/
