#include <bits/stdc++.h>
using namespace std;
int n, m, k, t, b[100100];
int d[100100];
void read(void) {
  cin >> k >> n >> m >> t;
  t = min(t, n);
  t = min(t, m);
}
void kill(void) {
  for (int i = 0; i < n; ++i) cin >> b[i];
  for (int j = 0; j <= m; ++j) d[j] = 0;
  for (int i = 0; i < t; ++i)
    for (int j = 0; j < n; ++j)
      if (1 + d[b[j] - 1] > d[b[j]]) {
        int x = b[j], k = x + 1;
        d[x] = d[x - 1] + 1;
        while (k <= m && d[k] < d[x]) d[k++] = d[x];
      }
  int ans = 0;
  for (int j = 0; j <= m; ++j) ans = max(ans, d[j]);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  read();
  for (int i = 0; i < k; ++i) kill();
  return 0;
}
