#include <bits/stdc++.h>
const int N = 100005;
int K, n, maxb, t;
int c[N];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void update(int x, int d) {
  while (x <= maxb) {
    if (d > c[x]) c[x] = d;
    x += x & -x;
  }
}
int get(int x) {
  int ans = 0;
  while (x > 0) {
    ans = std::max(ans, c[x]);
    x -= x & -x;
  }
  return ans;
}
int a[N], ans[N];
int cal() {
  memset(c, 0, sizeof(c));
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= t; i++)
    for (int j = 1; j <= n; j++) {
      int k = get(a[j] - 1) + 1;
      if (k > ans[j]) {
        ans[j] = k;
        update(a[j], k);
      }
    }
  return *std::max_element(ans + 1, ans + n + 1);
}
int main() {
  K = read(), n = read(), maxb = read(), t = read();
  t = std::min(maxb, t);
  while (K--) {
    for (int i = 1; i <= n; i++) a[i] = read();
    printf("%d\n", cal());
  }
}
