#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  for (long long _i = 0; _i < t; _i++) {
    long long n, k, d;
    cin >> n >> k >> d;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
    }
    map<long long, long long> m;
    for (long long i = 0; i < d; i++) {
      m[a[i]]++;
    }
    long long ans = (long long)m.size();
    for (long long i = d; i < n; i++) {
      m[a[i - d]]--;
      if (m[a[i - d]] == 0) {
        m.erase(a[i - d]);
      }
      m[a[i]]++;
      ans = min(ans, (long long)m.size());
    }
    cout << ans << endl;
  }
}
