#include <bits/stdc++.h>
using namespace std;
long long int n, k, d, t, a[200007];
int main() {
  scanf("%lld", &t);
  while (t--) {
    scanf("%lld %lld %lld", &n, &k, &d);
    for (long long int i = 0; i < n; ++i) scanf("%lld", &a[i]);
    map<long long int, long long int> occ;
    long long int distinct = 0;
    long long int ans;
    for (long long int i = 0; i < d; ++i) {
      occ[a[i]]++;
    }
    distinct = occ.size();
    ans = distinct;
    for (long long int i = d; i < n; ++i) {
      occ[a[i - d]]--;
      if (occ[a[i - d]] == 0) distinct--;
      occ[a[i]]++;
      if (occ[a[i]] == 1) distinct++;
      ans = min(ans, distinct);
    }
    printf("%lld\n", ans);
  }
}
