#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
int k, n, maxb, t, fen[MAXN], ans[MAXN], b[MAXN], cnt[MAXN];
int get(int x) {
  int ret = 0;
  for (; x; x -= x & -x) ret = max(ret, fen[x]);
  return ret;
}
void upd(int x, int val) {
  for (; x < MAXN; x += x & -x) fen[x] = max(fen[x], val);
}
int solve() {
  memset(fen, 0, sizeof fen);
  memset(ans, 0, sizeof ans);
  memset(cnt, 0, sizeof cnt);
  int ret = 0, unique = 0, nx;
  for (int i = 0; i < n; ++i) unique += (cnt[b[i]]++ == 0);
  for (int i = 0; i < t && ret < unique; ++i)
    for (int j = 0; j < n; ++j) {
      nx = get(b[j] - 1) + 1;
      if (nx != ans[j]) {
        ans[j] = nx;
        ret = max(ret, ans[j]);
        upd(b[j], nx);
      }
    }
  return ret;
}
int main() {
  cin >> k >> n >> maxb >> t;
  for (int i = 0; i < k; ++i) {
    for (int j = 0; j < n; ++j) cin >> b[j];
    cout << solve() << '\n';
  }
}
