#include <bits/stdc++.h>
using namespace std;
void readn(int &x) {
  char c;
  x = 0;
  do {
    c = getchar();
  } while (c < '0' || c > '9');
  do {
    x = x * 10 + c - '0';
    c = getchar();
  } while (c <= '9' && c >= '0');
}
const int MAXN = 101 * 1000;
int k, n, maxb, t, out = 0;
int a[MAXN], fen[MAXN], v[MAXN];
inline void add(int pos, int val) {
  if (val > out) out = val;
  v[pos] = val;
  while (pos <= maxb) {
    if (fen[pos] < val) fen[pos] = val;
    pos += pos & -pos;
  }
}
inline int rmax(int pos) {
  int tot = 0;
  while (pos) {
    if (tot < fen[pos]) tot = fen[pos];
    pos -= pos & -pos;
  }
  return tot;
}
int solve() {
  memset(fen, 0, sizeof fen);
  memset(v, 0, sizeof v);
  out = 0;
  for (register int rep = (0); rep < (int)(t); ++rep)
    for (register int i = (0); i < (int)(n); ++i)
      if (a[i]) {
        add(a[i], rmax(a[i] - 1) + 1);
        if (rep + 1 >= a[i] || v[a[i]] == a[i]) a[i] = 0;
        if (out == n || out == maxb) break;
      }
  return out;
}
int main() {
  scanf("%d %d %d %d", &k, &n, &maxb, &t);
  t = min(n, min(t, maxb));
  while (k--) {
    for (register int i = (0); i < (int)(n); ++i) readn(a[i]);
    printf("%d\n", solve());
  }
  return 0;
}
