#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int K, n, mx, T, a[maxn], f[maxn];
int main() {
  scanf("%d %d %d %d", &K, &n, &mx, &T);
  T = min({T, n, mx});
  while (K--) {
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    for (int t = 1; t <= T; t++) {
      for (int i = 1; i <= n; i++) {
        f[a[i]] = f[a[i] - 1] + 1;
        for (int j = a[i] + 1; j <= mx && f[j] < f[a[i]]; j++) {
          f[j] = f[a[i]];
        }
      }
    }
    printf("%d\n", f[mx]);
  }
  return 0;
}
