#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long wer = 0; wer < t; wer++) {
    long long n, k, d;
    cin >> n >> k >> d;
    vector<long long> v(n);
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
    }
    map<long long, long long> m;
    long long ans = 0;
    long long sum = 0;
    for (long long i = 0; i < d; i++) {
      long long x = v[i];
      if (m[x] == 0) {
        sum++;
      }
      m[x]++;
    }
    ans = sum;
    for (long long i = d; i < n; i++) {
      long long x = v[i];
      long long y = v[i - d];
      if (m[x] == 0) {
        sum++;
      }
      m[x]++;
      if (m[y] == 1) {
        sum--;
      }
      m[y]--;
      ans = min(ans, sum);
    }
    cout << ans << "\n";
  }
  return 0;
}
