#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-8;
int k, n, maxb, t;
int a[300000];
int b[300000];
int mi[300000];
int last[300000];
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  for (int now = 1; now <= k; ++now) {
    for (int i = 0; i < n; ++i) {
      scanf("%d", &a[i]);
      b[i] = a[i];
      last[i] = 0;
    }
    sort(b, b + n);
    int diff = unique(b, b + n) - b;
    for (int i = 0; i < n; ++i) {
      a[i] = lower_bound(b, b + diff, a[i]) - b;
    }
    int maxAnswer = diff;
    if (t >= maxAnswer) {
      printf("%d\n", maxAnswer);
      continue;
    }
    for (int i = 0; i <= maxAnswer; ++i) {
      mi[i] = 0x7fffffff;
    }
    mi[0] = 0;
    int ans = 0;
    vector<int> nextA;
    for (int i = 0; i < n; ++i) {
      if (i == 0 || a[i] != a[i - 1]) {
        nextA.push_back(a[i]);
      }
    }
    for (int i = 0; i < t && i < maxAnswer; ++i) {
      int *ptr = a;
      for (int j = 0; j < n; ++j, ++ptr) {
        register int p = *ptr;
        int low = last[j], high = maxAnswer - 1;
        if (last[j] + 1 == p + 1) {
          low = high = last[j];
        }
        while (low < high) {
          int mid = 1 + ((low + high) >> 1);
          if (mi[mid] < p) {
            low = mid;
          } else {
            high = mid - 1;
          }
        }
        last[j] = low;
        if (low + 1 > ans) {
          ans = low + 1;
          if (ans == maxAnswer) {
            break;
          }
        }
        if (p < mi[low + 1]) {
          mi[low + 1] = p;
        }
      }
      if (ans == maxAnswer) {
        break;
      }
    }
    cout << ans << endl;
  }
}
