#include <bits/stdc++.h>
using namespace std;
int a[100011], b[100011], f[100011];
map<int, int> Hash;
int tj, dt, n, m, T, t, tot, i, j, tmp, ans;
int main() {
  scanf("%d%d%d%d", &dt, &n, &m, &T);
  for (tj = 1; tj <= dt; tj++) {
    Hash.clear();
    t = 0;
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      if (!Hash[a[i]]) b[++t] = a[i], Hash[a[i]] = 1;
    }
    sort(b + 1, b + 1 + t);
    if (T >= t)
      printf("%d\n", t);
    else {
      for (i = 1; i <= t; i++) Hash[b[i]] = i;
      for (i = 1; i <= n; i++) a[i] = Hash[a[i]];
      ans = 0;
      memset(f, 0, sizeof(f));
      memset(b, 0, sizeof(b));
      for (i = 1; i <= T; i++) {
        for (j = 1; j <= n; j++) {
          while (f[a[j]] <= ans && b[f[a[j]]] < a[j]) f[a[j]]++;
          b[f[a[j]]] = a[j];
          ans = max(ans, f[a[j]]);
          if (ans == t) break;
        }
        if (ans == t) break;
      }
      printf("%d\n", ans);
    }
  }
}
