#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int k, n, maxb, t, num[N], c[N], f[N], vis[N];
inline void update(int x, int b) {
  for (; x <= maxb; x += x & (-x)) c[x] = max(c[x], b);
}
inline int query(int x) {
  int q = 0;
  for (; x; x -= x & (-x)) q = max(q, c[x]);
  return q;
}
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  while (k--) {
    int res = 0, ans = 0;
    memset(c, 0, sizeof c);
    memset(f, 0, sizeof f);
    for (int i = 1; i <= n; ++i) {
      scanf("%d", &num[i]);
      if (vis[num[i]] != k + 1) res++;
      vis[num[i]] = k + 1;
    }
    if (t >= res) {
      printf("%d\n", res);
      continue;
    }
    for (int i = 1; i <= t; ++i)
      for (int j = 1; j <= n; ++j) {
        int p = query(num[j] - 1) + 1;
        if (p > f[j]) {
          f[j] = p;
          ans = max(ans, p);
          update(num[j], p);
          if (ans == res) break;
        }
      }
    printf("%d\n", ans);
  }
  return 0;
}
