#include <bits/stdc++.h>
using namespace std;
int countDistinct(int arr[], int k, int n) {
  unordered_map<int, int> hm;
  set<int> val;
  int dist_count = 0;
  for (int i = 0; i < k; i++) {
    if (hm[arr[i]] == 0) dist_count++;
    hm[arr[i]] += 1;
  }
  val.insert(dist_count);
  for (int i = k; i < n; i++) {
    if (hm[arr[i - k]] == 1) {
      dist_count--;
    }
    hm[arr[i - k]] -= 1;
    if (hm[arr[i]] == 0) {
      dist_count++;
    }
    hm[arr[i]] += 1;
    val.insert(dist_count);
  }
  return *val.begin();
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, d;
    cin >> n >> k >> d;
    int arr[n];
    for (int i = 0; i < n; ++i) {
      cin >> arr[i];
    }
    cout << countDistinct(arr, d, n) << endl;
  }
  return 0;
}
