#include <bits/stdc++.h>
using namespace std;
int nq, n, m, t, tot, ans;
int a[100010], sa[100010], g[100010], f[20000010];
int main() {
  int i, j, q;
  scanf("%d%d%d%d", &nq, &n, &m, &t);
  for (q = 1; q <= nq; q++) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      sa[i] = a[i];
    }
    sort(sa + 1, sa + n + 1);
    tot = 0;
    for (i = 1; i <= n; i++)
      if (sa[i] != sa[i - 1]) sa[++tot] = sa[i];
    for (i = 1; i <= n; i++)
      a[i] = lower_bound(sa + 1, sa + tot + 1, a[i]) - sa;
    memset(f, 0, sizeof(f));
    memset(g, 0, sizeof(g));
    ans = 0;
    for (i = 1; i <= (long long)n * t && i <= n * tot; i++) {
      f[i] = g[a[(i - 1) % n + 1] - 1] + 1;
      ans = max(ans, f[i]);
      j = a[(i - 1) % n + 1];
      while (j <= tot && g[j] < f[i]) {
        g[j] = f[i];
        j++;
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
