#include <bits/stdc++.h>
using namespace std;
int k, n, m, T, i, j, L, wz, dp[100005], ans, MIN, DP[100005];
struct node {
  int x, y;
} a[100005];
int cmp(node i, node j) { return i.x < j.x; }
int main() {
  scanf("%d%d%d%d", &k, &n, &m, &T);
  while (k--) {
    for (i = 1; i <= n; i++) scanf("%d", &a[i].x);
    for (i = 1; i <= n; i++) a[i].y = i;
    sort(a + 1, a + n + 1, cmp);
    for (i = 1; i <= n; i++) dp[i] = 1;
    ans = 1;
    for (i = 2; i <= m; i++) {
      L = 1;
      MIN = T + 1;
      for (j = 1; j <= n; j++) {
        DP[j] = MIN + (wz > a[j].y);
        if (DP[j] <= T) ans = i;
        if (a[j].x != a[j + 1].x) {
          while (L <= j) {
            if (dp[L] < MIN) {
              MIN = dp[L];
              wz = a[L].y;
            } else if (dp[L] == MIN)
              wz = min(wz, a[L].y);
            L++;
          }
        }
      }
      for (j = 1; j <= n; j++) dp[j] = DP[j];
    }
    cout << ans << endl;
  }
  return 0;
}
