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 double eps = 1e-6;
const double PI = 3.14159265358979323846264338f;
const double pi = acos(-1.0);
const int inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const int MAXN = 100010;
inline int read() {
  int c = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    c = c * 10 + ch - '0';
    ch = getchar();
  }
  return c * f;
}
int k, n, maxb, t, cnt, ANS;
int a[MAXN], vis[MAXN], dp[MAXN], bit[MAXN];
inline void init() {
  memset(vis, 0, sizeof(vis));
  memset(bit, 0, sizeof(bit));
  memset(dp, 0, sizeof(dp));
  cnt = 0;
  ANS = 0;
}
inline int lowbit(const int &x) { return x & (-x); }
void add(int x, const int &y) {
  for (; x <= maxb; x += lowbit(x)) {
    bit[x] = max(bit[x], y);
  }
}
inline int ask(int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans = max(ans, bit[x]);
  return ans;
}
int main() {
  k = read(), n = read(), maxb = read(), t = read();
  while (k--) {
    init();
    for (int i = 1; i <= n; i++) {
      a[i] = read();
      if (!vis[a[i]]) ++cnt, vis[a[i]] = 1;
    }
    if (cnt <= t) {
      printf("%d\n", cnt);
      continue;
    }
    for (int i = 1; i <= t; i++) {
      for (int j = 1; j <= n; j++) {
        int tmpAns = ask(a[j] - 1) + 1;
        if (tmpAns > dp[j]) {
          dp[j] = tmpAns;
          add(a[j], tmpAns);
          ANS = max(ANS, tmpAns);
        }
      }
      if (ANS >= cnt) break;
    }
    printf("%d\n", ANS);
  }
  return 0;
}
