#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int a[N], dp[N];
int k, n, maxb, t, tot;
inline void solve() {
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(dp, 0, sizeof(dp));
  if (t >= n || t >= maxb) {
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (!dp[a[i]]) {
        ans++;
        dp[a[i]] = 1;
      }
    }
    printf("%d\n", ans);
  } else {
    dp[maxb + 1] = (1 << 30);
    for (int w = 1; w <= t; w++) {
      for (int i = 1; i <= n; i++) {
        dp[a[i]] = dp[a[i] - 1] + 1;
        for (int j = a[i] + 1; dp[j] < dp[j - 1]; dp[j] = dp[j - 1], j++)
          ;
      }
    }
    printf("%d\n", dp[maxb]);
  }
}
int main() {
  scanf("%d%d%d%d", &k, &n, &maxb, &t);
  while (k--) solve();
  return 0;
}
