#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 5;
int k, n, maxb, t;
int b[maxn], c[maxn], a[maxn], f[maxn];
void solved(int nT) {
  for (int i = 0; i < n; ++i) {
    scanf("%d", &b[i]);
    a[i] = b[i];
  }
  sort(a, a + n);
  int tn = unique(a, a + n) - a;
  if (t >= tn) {
    cout << tn << endl;
    return;
  }
  for (int i = 0; i < n; ++i) {
    b[i] = lower_bound(a, a + tn, b[i]) - a;
  }
  memset(f, 0, tn << 2);
  for (int ct = 0; ct < t; ++ct) {
    for (int i = 0; i < n; ++i) {
      int tmp = (b[i] == 0) ? 0 : f[b[i] - 1];
      int j = b[i];
      while (j < tn && f[j] == tmp) {
        ++f[j++];
      }
    }
  }
  cout << f[tn - 1] << endl;
}
int main() {
  scanf("%d %d %d %d", &k, &n, &maxb, &t);
  for (int nT = 1; nT <= k; ++nT) {
    solved(nT);
  }
  return 0;
}
