#include <bits/stdc++.h>
using namespace std;
int stmp;
const int MAXB = 100000;
const int INF = 1000000001;
int vis[MAXB + 1];
vector<int> arr;
int k, n, maxb, t, _t;
int z;
inline int lis() {
  vector<int> L(z, INF);
  for (int s = 0; s < (t); ++s) {
    for (int i = 0; i < ((int)(arr).size()) && L.back() == INF; ++i)
      *lower_bound((L).begin(), (L).end(), arr[i]) = arr[i];
    int c = 0;
    for (int i = 0; i < (((int)(arr).size())); ++i)
      if (arr[i] == L[s])
        ++c;
      else
        arr[i - c] = arr[i];
    arr.erase(arr.end() - c, arr.end());
  }
  return find((L).begin(), (L).end(), INF) - L.begin();
}
int main(int argc, char *argv[]) {
  stmp = scanf("%d %d %d %d", &k, &n, &maxb, &_t);
  for (int c = (1); c <= (k); ++c) {
    arr.resize(n);
    int rb = 0;
    for (int i = 0; i < (n); ++i) {
      stmp = scanf("%d", &arr[i]);
      if (vis[arr[i]] != c) ++rb;
      vis[arr[i]] = c;
    }
    arr.resize(unique((arr).begin(), (arr).end()) - arr.begin());
    z = rb;
    t = min(_t, z);
    printf("%d\n", t < z ? lis() : z);
  }
  return 0;
}
