#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int k, n, maxb, t;
int b[maxn], num[maxn], dp[maxn];
void solve() {
  if (t >= maxb || t >= n) {
    sort(b, b + n);
    cout << unique(b, b + n) - b << endl;
  } else {
    int a, len = 0;
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < t; i++) {
      for (int j = 0; j < n; j++) {
        a = b[j];
        for (; num[dp[a]] < a && dp[a] <= len; dp[a]++)
          ;
        num[dp[a]] = a;
        len = max(len, dp[a]);
      }
    }
    cout << len << endl;
  }
}
int main() {
  cin >> k >> n >> maxb >> t;
  for (int i = 0; i < k; i++) {
    for (int j = 0; j < n; j++) scanf("%d", &b[j]);
    solve();
  }
}
