#include <bits/stdc++.h>
using namespace std;
const int N = 500010;
int k, n, maxb, t, b[N], tot = 1, dp[N << 2], rec[N << 2];
void update(int i, int x) {
  while (i <= tot) {
    dp[i] = max(dp[i], x);
    i += i & -i;
  }
}
int sum(int i) {
  int ret = 0;
  while (i) {
    ret = max(ret, dp[i]);
    i -= i & -i;
  }
  return ret;
}
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  t = min(t, maxb);
  while (tot <= maxb) tot <<= 1;
  while (k--) {
    memset(dp, 0, sizeof(dp));
    memset(rec, 0, sizeof(rec));
    memset(b, 0, sizeof(b));
    for (int i = 0; i < n; i++) scanf("%d", &b[i]);
    for (int i = 1; i <= t; i++)
      for (int j = 0; j < n; j++) {
        int tmp = sum(b[j] - 1);
        if (tmp >= rec[j]) {
          update(b[j], tmp + 1);
          rec[j] = tmp + 1;
        }
      }
    printf("%d\n", sum(tot));
  }
  return 0;
}
