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>
void get_int(T &x) {
  char t = getchar();
  bool neg = false;
  x = 0;
  for (; (t > '9' || t < '0') && t != '-'; t = getchar())
    ;
  if (t == '-') neg = true, t = getchar();
  for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
  if (neg) x = -x;
}
template <typename T>
void print_int(T x) {
  if (x < 0) putchar('-'), x = -x;
  short a[20] = {}, sz = 0;
  while (x > 0) a[sz++] = x % 10, x /= 10;
  if (sz == 0) putchar('0');
  for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
const double pi = acos(-1.0);
int k, n, maxb, t, tb;
int cnt[100111], a[100111], dp[100111], ndp[100111], bit[100111];
void add(int x, int v) {
  for (; x <= tb; x += x & -x) bit[x] = max(bit[x], v);
}
int query(int x) {
  int ret = 0;
  for (; x > 0; x -= x & -x) ret = max(ret, bit[x]);
  return ret;
}
void solve() {
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    get_int(a[i]);
    cnt[a[i]]++;
  }
  tb = 0;
  for (int i = 1; i <= maxb; i++) tb += (cnt[i] > 0);
  if (min(tb, n) <= t) {
    printf("%d\n", min(tb, n));
    return;
  }
  vector<int> v;
  for (int i = 1; i <= n; i++) v.push_back(a[i]);
  sort(v.begin(), v.end());
  v.erase(unique(v.begin(), v.end()), v.end());
  for (int i = 1; i <= n; i++)
    a[i] = upper_bound(v.begin(), v.end(), a[i]) - v.begin();
  tb = v.size() + 1;
  for (int i = 1; i <= n; i++) dp[i] = 1;
  int ans = 0;
  memset(bit, 0, sizeof(bit));
  for (int _ = 0; _ < t; _++) {
    for (int i = 1; i <= n; i++) {
      int tans = query(a[i] - 1) + 1;
      ans = max(ans, tans);
      add(a[i], tans);
    }
  }
  print_int(ans), puts("");
}
int main() {
  get_int(k), get_int(n);
  get_int(maxb), get_int(t);
  for (int i = 1; i <= k; i++) solve();
  return 0;
}
