#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(0);
  int k, n, maxb, t;
  cin >> k >> n >> maxb >> t;
  for (int i = 0; i < k; ++i) {
    vector<int> b(n);
    for (int j = 0; j < n; ++j) {
      cin >> b[j];
      --b[j];
    }
    vector<vector<int> > nast(n, vector<int>(maxb, INF));
    nast[n - 1][b[n - 1]] = n - 1;
    for (int j = n - 2; j >= 0; --j) {
      for (int l = 0; l < maxb; ++l) nast[j][l] = nast[j + 1][l];
      nast[j][b[j]] = j;
    }
    vector<vector<int> > dp(n + 1, vector<int>(maxb, INF));
    for (int j = 0; j < maxb; ++j) dp[1][j] = nast[0][j];
    for (int j = 1; j < maxb; ++j) dp[1][j] = min(dp[1][j], dp[1][j - 1]);
    for (int j = 2; j <= n; ++j) {
      for (int l = 1; l < maxb; ++l) {
        int ost = dp[j - 1][l - 1];
        if (ost == INF) {
          dp[j][l] = dp[j][l - 1];
          continue;
        }
        int kol = nast[ost % n][l];
        if (kol != INF)
          dp[j][l] = ost - (ost % n) + kol;
        else {
          kol = nast[0][l];
          if (kol != INF) dp[j][l] = ost - (ost % n) + n + kol;
        }
        dp[j][l] = min(dp[j][l - 1], dp[j][l]);
      }
    }
    int odp;
    for (int j = 1; j <= n; ++j)
      if (dp[j][maxb - 1] != INF && dp[j][maxb - 1] < (long long)n * t) odp = j;
    cout << odp << endl;
  }
  return 0;
}
