#include <bits/stdc++.h>
using namespace std;
const int Mod = 1e9 + 7;
inline int FIX(long long a) { return (a % Mod + Mod) % Mod; }
int k, n, maxb, t;
int limit;
int b[100000 + 5];
int a[100000 + 5];
void add(int p, int v) {
  p = maxb - p + 1;
  for (int i = p; i <= maxb; i += (i & -i)) {
    a[i] = max(a[i], v);
  }
}
int query(int p) {
  p = maxb - p + 1;
  int ret = 0;
  for (int i = p; i >= 1; i -= (i & -i)) {
    ret = max(ret, a[i]);
  }
  return ret;
}
int ans[100000 + 5];
int main() {
  cin >> k >> n >> maxb >> t;
  while (k--) {
    for (int i = 1; i <= n; i++) {
      scanf("%d", &b[i]);
    }
    limit = min(t - 1, maxb) + 2;
    int M = min(t - 1, maxb);
    memset(a, 0, sizeof(a));
    memset(ans, 0, sizeof(ans));
    for (int j = 0; j <= M; j++) {
      for (int i = n; i >= 1; i--) {
        int cur = query(b[i] + 1) + 1;
        if (cur > ans[i]) {
          ans[i] = cur;
          add(b[i], cur);
        }
      }
    }
    cout << *max_element(ans + 1, ans + n + 1) << endl;
  }
  return 0;
}
