#include <bits/stdc++.h>
using namespace std;
int a[101010];
int f[101010];
bool visit[101010];
int main() {
  int q, n, maxb, t;
  scanf("%d %d %d %d", &q, &n, &maxb, &t);
  t = min(t, maxb);
  while (q--) {
    memset(f, 0, sizeof(f));
    maxb = 0;
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      maxb = max(maxb, a[i]);
      visit[a[i]] = 1;
    }
    for (int i = 1; i <= t; i++)
      for (int j = 1; j <= n; j++)
        for (int k = a[j]; k <= maxb && f[k] == f[a[j] - 1]; k++) f[k]++;
    printf("%d\n", f[maxb]);
  }
  return 0;
}
