#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N], f[N], n, m, q, t;
int main() {
  for (scanf("%d%d%d%d", &q, &n, &m, &t), t = min(t, m); q--;) {
    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; j <= n; j++)
        for (int k = a[j]; k <= m && f[k] == f[a[j] - 1]; f[k++]++)
          ;
    printf("%d\n", f[m]);
  }
  return 0;
}
