#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void smax(T &a, U b) {
  if (a < b) a = b;
}
int a[100100], b[100100], B[100100], nn;
int main() {
  int T, n, maxb, t;
  scanf("%d%d%d%d", &T, &n, &maxb, &t);
  while (T--) {
    for (int i = 0; i < n; i++) {
      scanf("%d", a + i);
      b[i] = a[i];
    }
    sort(b, b + n);
    nn = unique(b, b + n) - b;
    if (min(n, maxb) <= t) {
      printf("%d\n", nn);
      continue;
    }
    for (int i = 0; i < n; i++) a[i] = lower_bound(b, b + nn, a[i]) - b;
    for (int i = 0; i <= nn; i++) B[i] = 0;
    int ans = 0;
    for (int i = 0; i < n * t; i++) {
      int u = a[i % n];
      for (int j = u + 1; j <= nn && B[u] + 1 > B[j]; j++) B[j] = B[u] + 1;
    }
    cout << B[nn] << endl;
  }
  return 0;
}
