#include <bits/stdc++.h>
using namespace std;
int K, N, B, T, a[100005], p[100005], *f[100005], *q[100005];
int calc() {
  memset(p, 0, sizeof(p));
  for (int i = 1; i <= B; i++) f[1][i] = 1e9;
  for (int i = 1; i <= N; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= N; i++)
    if (!p[a[i]]) p[a[i]] = N + i, f[1][a[i]] = i;
  for (int i = N; i >= 0; i--) {
    for (int j = 1; j <= B; j++) q[i][j] = p[j];
    p[a[i]] = i;
  }
  for (int i = 2; i <= N; i++)
    for (int j = 1, m = 1e9, mm; j <= B; j++)
      mm = (m - 1) % N + 1, f[i][j] = q[mm][j] ? m + q[mm][j] - mm : 1e9,
      m = min(m, f[i - 1][j]);
  for (int i = N; i; i--)
    for (int j = 1; j <= B; j++)
      if (f[i][j] <= N * T) return i;
}
void doit() {
  scanf("%d%d%d%d", &K, &N, &B, &T), T = min(T, B);
  for (int i = 0; i <= N; i++) f[i] = new int[B + 5], q[i] = new int[B + 5];
  for (int i = 1; i <= K; i++) printf("%d\n", calc());
}
int main() {
  doit();
  return 0;
}
