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 <typename T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-9;
const int INF = 1e9;
struct Mass {
  int a[(int)3e7 + 10 + (int)1e5];
  int base;
  Mass() {
    for (int i = 0; i < (int)(int)3e7 + 10 + 1e5; ++i) {
      a[i] = INF;
    }
  }
  Mass(int base) : base(base) {}
  int* operator[](int i) { return a + i * base; }
};
int calc_maxb(int n) { return (2e7 + n - 1) / n; }
int n, maxb, t;
int b[(int)2e5];
int first[(int)2e5];
Mass jskdfksdhfjkdsjksdjkgf;
Mass dp;
int solve() {
  int max_len = min(n, maxb);
  for (int x = 1; x <= maxb; ++x) {
    first[x] = -1;
  }
  for (int i = 0; i < (int)n; ++i) {
    if (first[b[i]] == -1) {
      first[b[i]] = i;
    }
  }
  for (int x = 1; x <= maxb; ++x) {
    jskdfksdhfjkdsjksdjkgf[n][x] = -1;
  }
  for (int i = ((int)n) - 1; i >= 0; --i) {
    for (int x = 1; x <= maxb; ++x) {
      jskdfksdhfjkdsjksdjkgf[i][x] = jskdfksdhfjkdsjksdjkgf[i + 1][x];
    }
    if (i < n - 1) {
      jskdfksdhfjkdsjksdjkgf[i][b[i + 1]] = i + 1;
    }
  }
  for (int last = 1; last <= maxb; ++last) {
    dp[1][last] = dp[1][last - 1];
    if (first[last] != -1) {
      dp[1][last] = min(dp[1][last], first[last]);
    }
  }
  for (int len = 2; len <= max_len; ++len) {
    for (int last = 2; last <= maxb; ++last) {
      dp[len][last] = dp[len][last - 1];
      if (first[last] == -1) {
        continue;
      }
      int koeuigrihjdkjdfj = dp[len - 1][last - 1];
      int real_prev = koeuigrihjdkjdfj % n;
      if (jskdfksdhfjkdsjksdjkgf[real_prev][last] != -1) {
        dp[len][last] =
            min(dp[len][last], (koeuigrihjdkjdfj / n) * n +
                                   jskdfksdhfjkdsjksdjkgf[real_prev][last]);
      } else {
        dp[len][last] =
            min(dp[len][last], (1 + (koeuigrihjdkjdfj / n)) * n + first[last]);
      }
    }
  }
  int ans = 0;
  long long L = n * 1ll * t - 1;
  for (int len = 1; len <= max_len; ++len) {
    for (int last = 1; last <= maxb; ++last) {
      if (dp[len][last] < INF && dp[len][last] <= L) {
        ans = max(ans, len);
      }
    }
  }
  return ans;
}
int main() {
  int k;
  cin >> k >> n >> maxb >> t;
  jskdfksdhfjkdsjksdjkgf = Mass(maxb + 2);
  dp = Mass(maxb + 2);
  for (int it = 0; it < (int)k; ++it) {
    for (int i = 0; i < (int)n; ++i) {
      scanf("%d", &b[i]);
    }
    printf("%d\n", solve());
  }
  return 0;
}
