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;
template <class T>
inline void input(T &x) {
  register char c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
inline long long bigmod(long long p, long long e, long long M) {
  long long ret = 1;
  for (; e > 0; e >>= 1) {
    if (e & 1) ret = (ret * p) % M;
    p = (p * p) % M;
  }
  return ret;
}
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T modinverse(T a, T M) {
  return bigmod(a, M - 2, M);
}
const long long INF = 1e15;
const int N = 1e5 + 5;
vector<vector<long long> > dp;
vector<vector<long long> > Nxt;
int Map[N], Temp[N];
long long n, k, maxb, t;
int a[N];
bool vis[N];
int Pivot[2][N];
int nc[2];
long long Find(long long pos, int x) {
  if (Map[x] < 0) return -1;
  return pos + Nxt[pos % n][x];
}
int main() {
  cin >> k >> n >> maxb >> t;
  Nxt.resize(n + 1);
  for (int i = 0; i <= n; i++) Nxt[i].resize(maxb + 1);
  dp.resize(2);
  dp[1].resize(maxb + 1);
  dp[0].resize(maxb + 1);
  t = min(t, n);
  for (int i = 0; i < k; i++) {
    memset(Map, -1, sizeof(Map));
    memset(Temp, -1, sizeof(Temp));
    for (int i = 1; i <= maxb; i++) dp[1][i] = INF;
    nc[0] = nc[1] = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      if (Map[a[i]] < 0)
        Map[a[i]] = i, dp[1][a[i]] = i, Pivot[1][nc[1]++] = a[i];
    }
    sort(Pivot[1], Pivot[1] + nc[1]);
    for (int i = n - 1; i >= 0; i--) {
      for (int j = 1; j <= maxb; j++) {
        if (j > a[i]) {
          if (Temp[j] > 0) {
            Nxt[i][j] = Temp[j] - i;
          } else if (Map[j] >= 0)
            Nxt[i][j] = (n - i) + Map[j];
        }
      }
      Temp[a[i]] = i;
    }
    int ans = 1;
    int now = 1;
    long long ptr;
    for (int i = 2; i <= n; i++) {
      ptr = INF;
      now = now ^ 1;
      nc[now] = 0;
      for (int k = 0; k < nc[now ^ 1]; k++) {
        int j = Pivot[now ^ 1][k];
        dp[now][j] = INF;
        if (ptr < INF && Find(ptr, j) >= 0) {
          dp[now][j] = Find(ptr, j);
        }
        ptr = min(ptr, dp[now ^ 1][j]);
        if (dp[now][j] < n * t) {
          ans = max(ans, i);
          Pivot[now][nc[now]++] = j;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
