#include <bits/stdc++.h>
using namespace std;
void run();
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  run();
  return 0;
}
inline void solve() {
  int n, k, d;
  cin >> n >> k >> d;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int ans = k;
  map<int, int> store;
  int temp = 0;
  for (int i = 0; i < n; i++) {
    if (store[a[i]] == 0) temp++;
    store[a[i]]++;
    if (i >= d) {
      if (store[a[i - d]] == 1) temp--;
      store[a[i - d]]--;
    }
    if (i >= d - 1) ans = min(ans, temp);
  }
  ans = min(ans, temp);
  cout << ans << '\n';
}
inline void run() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
