#include <bits/stdc++.h>
using namespace std;
int T, n, maxb, t, a[233333], f[233333];
int main() {
  scanf("%d%d%d%d", &T, &n, &maxb, &t);
  t = min(t, maxb);
  while (T--) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= maxb + 1; i++) f[i] = 0;
    for (int i = 1; i <= t * n; i++) {
      int d = a[(i - 1) % n + 1], ret = f[d] + 1;
      for (int i = d + 1; i <= maxb + 1 && ret > f[i]; i++) f[i] = ret;
    }
    printf("%d\n", f[maxb + 1]);
  }
}
