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