#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  vector<int> cnt(1000001);
  cin >> t;
  for (int x = 0; x < t; ++x) {
    int n, k, d;
    cin >> n >> k >> d;
    set<int> uniq;
    deque<int> pref;
    int ans = k + 1;
    int maxk = 0;
    for (int i = 0; i < n; ++i) {
      int cur;
      cin >> cur;
      maxk = max(maxk, cur);
      ++cnt[cur];
      if (cnt[cur] == 1) uniq.insert(cur);
      pref.emplace_back(cur);
      if (i >= d - 1) {
        ans = min(ans, (int)uniq.size());
        --cnt[pref.front()];
        if (cnt[pref.front()] == 0) uniq.erase(pref.front());
        pref.pop_front();
      }
    }
    cout << ans << '\n';
    memset(&cnt[0], 0, sizeof(cnt[0]) * (maxk + 1));
  }
  return 0;
}
