#include <bits/stdc++.h>
using namespace std;
int k, n, lim, t, a[110000], f[110000];
int main() {
  cin >> k >> n >> lim >> t;
  lim++;
  t = min(t, lim);
  while (k--) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 0; i <= lim; i++) f[i] = 0;
    for (int i = 1; i <= n * t; i++) {
      int z = a[(i - 1) % n + 1], t = f[z] + 1;
      for (int j = z + 1; j <= lim; j++) {
        if (f[j] >= t) break;
        f[j] = t;
      }
    }
    cout << f[lim] << endl;
  }
  return 0;
}
