#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long int t, n, k, d, i;
  cin >> t;
  while (t--) {
    cin >> n >> k >> d;
    vector<long long int> A(n);
    for (i = 0; i < n; i++) {
      cin >> A[i];
    }
    long long int dist = 0;
    map<long long int, long long int> mp;
    for (i = 0; i < d; i++) {
      mp[A[i]]++;
    }
    dist = mp.size();
    long long int dist1 = dist;
    for (i = d; i < n; i++) {
      if (mp[A[i - d]] == 1)
        mp.erase(A[i - d]);
      else
        mp[A[i - d]]--;
      mp[A[i]]++;
      if (mp.size() < dist) dist = mp.size();
    }
    cout << dist << "\n";
    A.clear();
  }
}
