#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, k, d;
  cin >> n >> k >> d;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  long long mn = 1e18;
  map<long long, long long> cnt;
  long long x = 0, y = d - 1;
  long long c = 0;
  for (long long i = x; i <= y; i++) {
    if (cnt.find(a[i]) == cnt.end()) c++;
    cnt[a[i]]++;
  }
  mn = min(mn, c);
  y++;
  x++;
  while (x <= n - d) {
    if (cnt[a[y]] == 0) c++;
    cnt[a[y]]++;
    cnt[a[x - 1]]--;
    if (cnt[a[x - 1]] == 0) c--;
    mn = min(mn, c);
    y++;
    x++;
  }
  cout << mn << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) solve();
}
