#include <bits/stdc++.h>
using namespace std;
int inp[100004], dp[100004];
int main() {
  int k, n, maxb, t, i, len, x, j;
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  t = min(t, n);
  t = min(t, maxb);
  len = t * n;
  while (k--) {
    for (i = 0; i < n; i++) scanf("%d", &inp[i]);
    for (i = 0; i <= maxb; i++) dp[i] = 0;
    for (i = 0; i < len; i++) {
      x = inp[i % n];
      for (j = x; j <= maxb && dp[j] == dp[x - 1]; j++) dp[j]++;
    }
    printf("%d\n", dp[maxb]);
  }
  return 0;
}
