#include <bits/stdc++.h>
using namespace std;
template <typename T>
using V = vector<T>;
int dp[120000], a[120000];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int k, n, maxb, t;
  cin >> k >> n >> maxb >> t;
  t = min(maxb, t);
  while (k--) {
    fill(dp, dp + maxb + 1, 0);
    dp[0] = 0;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    for (int i = 0; i < t * n; i++) {
      int v = a[i % n];
      for (int j = v; j <= maxb; j++) {
        if (dp[j] >= dp[v - 1] + 1) {
          break;
        }
        dp[j] = dp[v - 1] + 1;
      }
    }
    cout << dp[maxb] << endl;
  }
  return 0;
}
