#include <bits/stdc++.h>
using namespace std;
ifstream Cin("input.txt");
ofstream Cout("output.txt");
int main() {
  long long k, n, maxb, t, i, len, x, j, r[100000], dp[100001];
  cin >> k >> n >> maxb >> t;
  t = min(t, min(n, maxb));
  len = t * n;
  while (k--) {
    for (i = 0; i < n; i++) cin >> r[i];
    for (i = 0; i < maxb + 1; i++) dp[i] = 0;
    for (i = 0; i < len; i++) {
      x = r[i % n];
      for (j = x; j <= maxb && dp[j] == dp[x - 1]; j++) dp[j]++;
    }
    cout << dp[maxb] << endl;
  }
}
