#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 7;
const long double EPS = 1e-8;
const long long MAXI = 31;
const long long MOD = 16714589;
const long long MAXST = 2000000;
const long double PI = 3.14159265358979323;
long long a[2100000];
signed main() {
  {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(0);
    cerr << fixed << setprecision(10);
  };
  long long t;
  cin >> t;
  for (long long q = 0; q < t; q++) {
    long long n, k, d;
    cin >> n >> k >> d;
    for (long long i = 0; i < n; i++) cin >> a[i];
    long long l = 0, r = d - 1;
    map<long long, long long> p;
    for (long long i = 0; i < d; i++) p[a[i]]++;
    long long mi = p.size();
    while (r + 1 < n) {
      r++;
      p[a[r]]++;
      p[a[l]]--;
      if (p[a[l]] == 0) p.erase(a[l]);
      l++;
      mi = min(mi, (long long)p.size());
    }
    cout << mi << '\n';
  }
  return 0;
}
