#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
long double eps = (long double)1 / 1e9;
long long inf = 1e18, mod1 = 998244353, mod2 = 1e9 + 7;
long long sqr(long long a) { return a * a; }
long long gcd(long long a, long long b) { return !a ? b : gcd(b % a, a); }
long long binpow(long long a, long long b, long long mod) {
  return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod
                    : sqr(binpow(a, b / 2, mod)) % mod)
           : 1;
}
long long a[200001];
int main() {
  cout.tie(0), cin.tie(0), ios_base::sync_with_stdio(0);
  long long q, n, k, d, i, ans;
  cin >> q;
  while (q--) {
    cin >> n >> k >> d;
    for (i = 1; i <= n; i++) cin >> a[i];
    unordered_map<long long, long long> ump;
    ans = n;
    for (i = 1; i <= d; i++) {
      if (ump.find(a[i]) == ump.end()) ump.insert({a[i], 0});
      ump[a[i]]++;
    }
    ans = min(ans, (long long)ump.size());
    for (i = d + 1; i <= n; i++) {
      ump[a[i - d]]--;
      if (ump[a[i - d]] == 0) ump.erase(a[i - d]);
      if (ump.find(a[i]) == ump.end()) ump.insert({a[i], 0});
      ump[a[i]]++;
      ans = min(ans, (long long)ump.size());
    }
    cout << ans << '\n';
  }
  return 0;
}
