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>
#pragma comment(linker, "/STACK:200000000")
using namespace std;
template <typename T>
inline T Abs(T x) {
  return (x >= 0) ? x : -x;
}
template <typename T>
inline T sqr(T x) {
  return x * x;
}
template <typename T>
string toStr(T x) {
  stringstream st;
  st << x;
  string s;
  st >> s;
  return s;
}
const int INF = (int)1E9;
const long long INF64 = (long long)1E18;
const long double EPS = 1E-9;
const long double PI = 3.1415926535897932384626433832795;
const int MAXN = 100100;
vector<int> nexttttt[MAXN];
vector<long long> d[MAXN];
int n, B, t, a[MAXN];
long long findnexttttt(long long curPos, int valueForFind) {
  if (valueForFind >= B) return INF64;
  int nextttttPos = nexttttt[curPos % n + 1][valueForFind];
  if (nextttttPos < n)
    return (curPos / n) * n + nextttttPos;
  else {
    nextttttPos = nexttttt[0][valueForFind];
    if (nextttttPos >= n) return INF64;
    return (curPos / n + 1) * n + nextttttPos;
  }
}
int solve() {
  nexttttt[n].assign(B + 2, n);
  d[n].assign(B + 2, INF64);
  for (int pos = (int)(n)-1; pos >= 0; pos--) {
    d[pos].assign(B + 2, INF64);
    nexttttt[pos].assign((nexttttt[pos + 1]).begin(),
                         (nexttttt[pos + 1]).end());
    nexttttt[pos][a[pos]] = pos;
  }
  for (int pos = (int)(n)-1; pos >= 0; pos--) d[a[pos]][1] = pos;
  for (int v = 0; v < (int)(n); v++)
    for (int val = 0; val < (int)(B + 1); val++) {
      long long cur = d[v][val];
      if (cur > INF64 / 2) continue;
      d[v + 1][val] = min(d[v + 1][val], cur);
      d[v + 1][val + 1] = min(d[v + 1][val + 1], findnexttttt(cur, v + 1));
    }
  int ans = 0;
  for (int val = 0; val < (int)(B + 2); val++)
    if (d[n][val] < 1LL * n * t) ans = val;
  return ans;
}
int main() {
  int tests;
  cin >> tests >> n >> B >> t;
  for (int test = 0; test < (int)(tests); test++) {
    vector<int> X;
    for (int i = 0; i < (int)(n); i++) {
      scanf("%d", &a[i]);
      X.push_back(a[i]);
    }
    sort((X).begin(), (X).end());
    X.erase(unique((X).begin(), (X).end()), X.end());
    for (int i = 0; i < (int)(n); i++)
      a[i] = (int)(lower_bound((X).begin(), (X).end(), a[i]) - X.begin());
    cout << solve() << endl;
  }
  return 0;
}
