#include <bits/stdc++.h>
using namespace std;
int T, n, b, t, a[100010], f[100010];
int main() {
  cin >> T >> n >> b >> t;
  t = min(min(n, b), t);
  while (T--) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    memset(f, 0, sizeof(f));
    for (int i = 1; i <= t; i++)
      for (int j = 1, k; j <= n; j++)
        for (f[a[j]] = f[a[j] - 1] + 1, k = a[j] + 1; k <= b && f[a[j]] > f[k];
             k++)
          f[k] = f[a[j]];
    cout << f[b] << "\n";
  }
}
