#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int n, maxb, t, k, dp[maxn], b[maxn], DP[maxn];
int lowbit(int x) { return x & (-x); }
void update(int x, int y) {
  for (int i = x; i < maxn; i += lowbit(i)) dp[i] = max(dp[i], y);
}
int query(int x) {
  int Ans = 0;
  for (int i = x; i; i -= lowbit(i)) Ans = max(Ans, dp[i]);
  return Ans;
}
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  t = min(t, maxb);
  while (k--) {
    for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
    memset(dp, 0, sizeof(dp));
    memset(DP, 0, sizeof(DP));
    for (int i = 1; i <= t; i++) {
      for (int j = 1; j <= n; j++) {
        int tmp = query(b[j] - 1);
        if (tmp >= DP[j]) update(b[j], tmp + 1), DP[j] = tmp + 1;
      }
    }
    printf("%d\n", query(maxn - 1));
  }
}
