Maxim 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; 
  * <image> (1 ≤ i ≤ n × t), where operation <image> means taking the remainder after dividing number x by number y. 



Sequence s1, s2, ..., sr of length r is a subsequence of sequence a1, a2, ..., an, if there is such increasing sequence of indexes i1, i2, ..., ir (1 ≤ i1 < i2 < ... < ir ≤ n), that aij = sj. In other words, the subsequence can be obtained from the sequence by crossing out some elements.

Sequence s1, s2, ..., sr is increasing, if the following inequality holds: s1 < s2 < ... < sr.

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 ≤ 105; 1 ≤ t ≤ 109; n × maxb ≤ 2·107). Each of the next k lines contain n integers b1, b2, ..., bn (1 ≤ bi ≤ maxb). 

Note that for each variant of the sequence a the values n, maxb and t coincide, the only arrays bs 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
#include <bits/stdc++.h>
using namespace std;
const int N = 110000, inf = 1 << 29;
int i, j, k, l, m, n, o, p, nex[N], a[N], c[N], T, t, F[N], b[N];
vector<int> B[N];
struct arr {
  int x, y;
  arr() {}
  arr(int X, int Y) {
    x = X;
    y = Y;
  }
  inline bool operator<(const arr &t) const {
    return (x < t.x) || ((x == t.x) && (y < t.y));
  }
  inline void put() { printf("(%d %d) ", x, y); }
} f[4500], s[5][4500];
inline int read() {
  int o = 0;
  char c = getchar();
  while ((c < '0') || (c > '9')) c = getchar();
  while ((c >= '0') && (c <= '9')) {
    o = (o << 1) + (o << 3) + c - '0';
    c = getchar();
  }
  return o;
}
inline void Init() {
  for (i = 1; i <= n; i++) a[i] = c[i] = read();
  m = 0;
  sort(c + 1, c + n + 1);
  for (i = 1; i <= n; i++)
    if (c[i] != c[i - 1]) F[c[i]] = ++m;
  for (i = 1; i <= n; i++) a[i] = F[a[i]];
}
inline int Solve() {
  int ans = 0, top, Max, now, last, tt;
  Max = min(n, m);
  for (i = 0; i <= 1; i++)
    for (j = 1; j <= Max; j++) s[i][j] = arr(inf, n);
  s[0][0] = s[1][0] = arr(1, 0);
  for (i = 1; i <= m; i++) {
    for (j = 1; j <= n; j++) b[j] = 0;
    now = i & 1;
    last = now ^ 1;
    nex[n + 1] = 0;
    for (j = n; j >= 0; j--)
      if (a[j] == i) {
        top = j;
        nex[j] = j;
      } else
        nex[j] = nex[j + 1];
    for (j = 1; j <= Max; j++) {
      o = s[last][j - 1].x;
      p = s[last][j - 1].y;
      f[j] = arr(inf, n);
      k = nex[p];
      if (k)
        f[j] = arr(o, k);
      else if (o < t)
        f[j] = arr(o + 1, top);
    }
    for (j = 1; j <= Max; j++) {
      s[now][j] = s[last][j];
      if (f[j] < s[now][j]) s[now][j] = f[j];
      if ((f[j].x <= t) && (j > ans)) ans = j;
    }
  }
  return ans;
}
int main() {
  cin >> T >> n >> m >> t;
  while (T--) {
    Init();
    cout << Solve() << endl;
  }
  return 0;
}
