#include <bits/stdc++.h>
using namespace std;
const long long N = 2e6;
long long q, cnt[N];
signed main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> q;
  while (q--) {
    long long n, k, d, no = 0, res;
    cin >> n >> k >> d;
    vector<long long> a(n);
    for (long long i = 0; i < n; ++i) cin >> a[i];
    for (long long i = 0; i < d; ++i) {
      no += !cnt[a[i]];
      cnt[a[i]]++;
    }
    res = no;
    for (long long i = d; i < n; ++i) {
      cnt[a[i - d]]--;
      no -= !cnt[a[i - d]];
      no += !cnt[a[i]];
      cnt[a[i]]++;
      res = min(no, res);
    }
    cout << res << '\n';
    for (long long i = 0; i < n; ++i) cnt[a[i]] = 0;
  }
}
