#include <bits/stdc++.h>
using namespace std;
int a[100010], f[100010], t, maxb;
int LIS(const int &n) {
  int i, size = 1, ss;
  int l, r, z;
  f[0] = 0;
  for (int ti = 0; ti < t; ++ti) {
    ss = size;
    for (i = 0; i < n; ++i) {
      if (a[i] <= f[ti]) continue;
      l = ti;
      r = size;
      while (l + 1 < r) {
        z = (l + r) >> 1;
        if (f[z] < a[i])
          l = z;
        else
          r = z;
      }
      f[l + 1] = a[i];
      if (l == size - 1) size++;
    }
    if (size == ss) return size;
  }
  return size;
}
int main(void) {
  int i, n, T;
  scanf("%d", &T);
  scanf("%d%d%d", &n, &maxb, &t);
  t = min(maxb, t);
  while (T--) {
    for (i = 0; i < n; ++i) scanf("%d", &a[i]);
    printf("%d\n", LIS(n) - 1);
  }
  return 0;
}
