Package for this problem was not updated by the problem writer or Codeforces administration after we’ve upgraded the judging servers. To adjust the time limit constraint, solution execution time will be multiplied by 2. For example, if your solution works for 400 ms on judging servers, then value 800 ms will be displayed and used to determine the verdict.

Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

В условии задачи недавно были сделаны правки. Просмотреть изменения.

×
D. Maxim and Increasing Subsequence

time limit per test

6 secondsmemory limit per test

256 megabytesinput

standard inputoutput

standard outputMaxim loves sequences, especially those that strictly increase. He is wondering, what is the length of the longest increasing subsequence of the given sequence *a*?

Sequence *a* is given as follows:

- the length of the sequence equals
*n*×*t*; - (1 ≤
*i*≤*n*×*t*), where operation means taking the remainder after dividing number*x*by number*y*.

Sequence *s*_{1}, *s*_{2}, ..., *s*_{r} of length *r* is a subsequence of sequence *a*_{1}, *a*_{2}, ..., *a*_{n}, if there is such increasing sequence of indexes *i*_{1}, *i*_{2}, ..., *i*_{r} (1 ≤ *i*_{1} < *i*_{2} < ... < *i*_{r} ≤ *n*), that *a*_{ij} = *s*_{j}. In other words, the subsequence can be obtained from the sequence by crossing out some elements.

Sequence *s*_{1}, *s*_{2}, ..., *s*_{r} is increasing, if the following inequality holds: *s*_{1} < *s*_{2} < ... < *s*_{r}.

Maxim have *k* variants of the sequence *a*. Help Maxim to determine for each sequence the length of the longest increasing subsequence.

Input

The first line contains four integers *k*, *n*, *maxb* and *t* (1 ≤ *k* ≤ 10; 1 ≤ *n*, *maxb* ≤ 10^{5}; 1 ≤ *t* ≤ 10^{9}; *n* × *maxb* ≤ 2·10^{7}). Each of the next *k* lines contain *n* integers *b*_{1}, *b*_{2}, ..., *b*_{n} (1 ≤ *b*_{i} ≤ *maxb*).

Note that for each variant of the sequence *a* the values *n*, *maxb* and *t* coincide, the only arrays *b*s differ.

The numbers in the lines are separated by single spaces.

Output

Print *k* integers — the answers for the variants of the sequence *a*. Print the answers in the order the variants follow in the input.

Examples

Input

3 3 5 2

3 2 1

1 2 3

2 3 1

Output

2

3

3

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/26/2020 15:45:39 (f2).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|