#include <bits/stdc++.h>
using namespace std;
int T, n, maxb, t, a[100100], f[100100];
int main() {
  cin >> T >> n >> maxb >> t;
  t = min(t, n);
  while (T--) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(f, 0, sizeof(f));
    int ans = 0;
    for (int i = 1; i <= t; i++)
      for (int j = 1; j <= n; j++) {
        int t = a[j] + 1;
        f[a[j]] = max(f[a[j]], 1);
        while (f[t] < f[a[j]] + 1 && t <= maxb) f[t] = f[a[j]] + 1, t++;
        ans = max(f[a[j]], ans);
        if (f[a[j]] == maxb) break;
      }
    printf("%d\n", ans);
  }
}
