#include <bits/stdc++.h>
using namespace std;
const int INT_INF = (1U << 31) - 10000;
const int MAX_N = 100010;
int K, N, MAX_B, T;
int b[MAX_N], b_num;
int dp[MAX_N], dp_min[MAX_N];
set<int> s;
int solve() {
  fill_n(dp, MAX_N, INT_INF);
  fill_n(dp_min, MAX_N, 0);
  for (int i = 0; i < T; i++) {
    for (int j = 0; j < N; j++) {
      if (b[j] < i) continue;
      auto r = lower_bound(dp + dp_min[j], dp + N, b[j]);
      dp_min[j] = r - dp;
      *r = b[j];
    }
  }
  return (lower_bound(dp, dp + N, INT_INF) - dp);
}
int main(int argc, char *argv[]) {
  cin >> K >> N >> MAX_B >> T;
  for (int k = 0; k < K; k++) {
    s.clear();
    for (int i = 0; i < N; i++) {
      scanf("%d", &(b[i]));
      b[i]--;
      s.insert(b[i]);
    }
    b_num = s.size();
    if (T >= b_num) {
      printf("%d\n", b_num);
      continue;
    }
    printf("%d\n", solve());
  }
  return 0;
}
