#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long asd;
  cin >> asd;
  for (long long abc = 0; abc < asd; abc++) {
    long long n, k, d;
    cin >> n >> k >> d;
    long long a[n];
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      a[i]--;
    }
    unordered_map<long long, long long> have;
    for (long long i = 0; i < d; i++) {
      have[a[i]]++;
    }
    long long res = have.size();
    for (long long i = d; i < n; i++) {
      have[a[i - d]]--;
      if (!have[a[i - d]]) {
        have.erase(a[i - d]);
      }
      have[a[i]]++;
      res = min(res, (long long)have.size());
    }
    cout << res << "\n";
  }
  return 0;
}
