#include <bits/stdc++.h>
using namespace std;
const int maxn = 20000010;
int k, n, m, t;
int b[maxn];
int dp[maxn];
int gao[maxn];
int main() {
  while (~scanf("%d %d %d %d", &k, &n, &m, &t)) {
    t = min(t, min(n, m));
    while (k--) {
      for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
      for (int i = 1; i <= n + 10; i++) gao[i] = maxn;
      gao[0] = 0;
      int cnt = 0;
      int ans = 0;
      for (int j = 1; j <= t; j++)
        for (int i = 1; i <= n; i++) {
          cnt++;
          if (j > 1)
            dp[cnt] = dp[cnt - n] - 1;
          else
            dp[cnt] = 0;
          while (gao[dp[cnt] + 1] < b[i]) dp[cnt]++;
          dp[cnt]++;
          if (gao[dp[cnt]] > b[i]) gao[dp[cnt]] = b[i];
          ans = max(ans, dp[cnt]);
        }
      printf("%d\n", ans);
    }
  }
}
