#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
int c[maxn], ans[maxn];
int k, n, maxb, t;
int b[maxn];
void update(int x, int d) {
  for (; x <= maxb; x += x & -x) {
    if (d > c[x]) c[x] = d;
  }
}
int get(int x) {
  int ans = 0;
  for (; x > 0; x -= x & -x)
    if (c[x] > ans) ans = c[x];
  return ans;
}
void solve() {
  if (t >= maxb) {
    sort(b, b + n);
    cout << unique(b, b + n) - b << endl;
  } else {
    int x;
    memset(c, 0, sizeof(c));
    memset(ans, 0, sizeof(ans));
    for (int i = 0; i < t; i++) {
      for (int j = 0; j < n; j++) {
        x = get(b[j] - 1) + 1;
        if (x > ans[j]) {
          ans[j] = x;
          update(b[j], x);
        }
      }
    }
    cout << *max_element(ans, ans + n) << 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();
  }
  return 0;
}
