#include <bits/stdc++.h>
using namespace std;
int k, n, maxb, t;
int b[100010], flag[100010];
int main() {
  ios::sync_with_stdio(false);
  cin >> k >> n >> maxb >> t;
  t = min(t, min(n, maxb));
  for (int ti = 1; ti <= k; ti++) {
    for (int i = 1; i <= n; i++) cin >> b[i];
    for (int i = 0; i <= maxb; i++) flag[i] = 0;
    for (int i = 1; i <= t; i++)
      for (int j = 1; j <= n; j++)
        for (int k = b[j]; k <= maxb && flag[k] == flag[b[j] - 1]; k++)
          flag[k]++;
    cout << flag[maxb] << endl;
  }
  return 0;
}
