#include <bits/stdc++.h>
using namespace std;
int k, n, maxb, t, s, sum, a[100005], b[100005], f[100005], tree[100005];
int lowbit(int x) { return x & (-x); }
int find(int x) {
  int s = 0;
  for (; x; x -= lowbit(x)) s = max(tree[x], s);
  return s;
}
void gg(int x, int y) {
  for (; x <= maxb; x += lowbit(x)) tree[x] = max(tree[x], y);
}
int main() {
  cin >> k >> n >> maxb >> t;
  while (k--) {
    s = sum = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (b[a[i]] != k + 1) sum++;
      b[a[i]] = k + 1;
    }
    if (t >= sum) {
      cout << sum << endl;
      continue;
    }
    memset(tree, 0, sizeof(tree));
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= t; i++)
      for (int j = 1; j <= n; j++) {
        int c = find(a[j] - 1) + 1;
        if (c > f[j]) {
          f[j] = c;
          s = max(s, c);
          gg(a[j], c);
        }
        if (s > sum) break;
      }
    printf("%d\n", s);
  }
}
