#include <bits/stdc++.h>
const int maxn = 1e5 + 7;
using namespace std;
int k, n, maxb, t, sum, ans, i, j, c;
int a[maxn], b[maxn], tree[maxn], f[maxn];
int lowbit(int x) { return x & (-x); }
void updata(int x, int c) {
  while (x <= maxb) {
    tree[x] = max(tree[x], c);
    x += lowbit(x);
  }
}
int get(int x) {
  int c = 0;
  while (x > 0) {
    c = max(c, tree[x]);
    x -= lowbit(x);
  }
  return c;
}
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  while (k--) {
    sum = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (b[a[i]] != k + 1) sum++;
      b[a[i]] = k + 1;
    }
    if (t >= sum) {
      printf("%d\n", sum);
      continue;
    }
    ans = 0;
    for (i = 1; i <= maxn; i++) {
      tree[i] = 0;
      f[i] = 0;
    }
    for (i = 1; i <= t; i++)
      for (j = 1; j <= n; j++) {
        c = get(a[j] - 1) + 1;
        if (c > f[j]) {
          f[j] = c;
          ans = max(ans, c);
          updata(a[j], c);
        }
        if (ans >= sum) break;
      }
    printf("%d\n", ans);
  }
}
