#include <bits/stdc++.h>
using namespace std;
const int mxsz = 1e5;
int ts, n, m, mx, t, ans;
int a[mxsz + 5], dp[mxsz + 5];
void inline upd(int fm, int w) {
  for (int i = fm; i <= mx; ++i) {
    if (dp[i] < w)
      dp[i] = w;
    else
      break;
  }
}
void inline solve() {
  t = min(t, n);
  t = min(t, mx);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  m = n * t;
  ans = 0;
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < m; ++i) {
    int c = a[i % n];
    upd(c, dp[c - 1] + 1);
  }
  for (int i = 1; i <= mx; ++i) {
    ans = max(ans, dp[i]);
  }
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d%d%d", &ts, &n, &mx, &t);
  for (int cs = 1; cs <= ts; ++cs) solve();
}
