#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  cin >> T;
  for (int P = 0; P < T; P++) {
    int n, k, d;
    cin >> n >> k >> d;
    vector<int> ar(n);
    map<int, int> s;
    int count = 0;
    for (int i = 0; i < n; i++) {
      int tmp = 0;
      cin >> tmp;
      if (s.find(tmp) == s.end()) {
        s.insert(pair<int, int>(tmp, count));
        tmp = count;
        count++;
      } else {
        tmp = s.find(tmp)->second;
      }
      ar[i] = tmp;
    }
    vector<int> b(count, 0);
    int price = 0;
    for (int i = 0; i < d; i++) {
      if (b[ar[i]] == 0) {
        price++;
      }
      b[ar[i]]++;
    }
    int min_price = price;
    for (int i = d; i < n; i++) {
      if (b[ar[i - d]] == 1) {
        price--;
      }
      b[ar[i - d]]--;
      if (b[ar[i]] == 0) {
        price++;
      }
      b[ar[i]]++;
      min_price = min(min_price, price);
    }
    cout << min_price << "\n";
  }
  return 0;
}
