#include <bits/stdc++.h>
using namespace std;
void par(int a[], int n) {
  for (long long int i = 0; i < n; i++) {
    cout << a[i] << " ";
  }
}
void pv(vector<long long int> a) {
  for (long long int i = 0; i < a.size(); i++) {
    cout << a[i] << " ";
  }
}
long long int ceiling(long long int n, long long int m) {
  if (n % m == 0)
    return n / m;
  else
    return n / m + 1;
}
long long int mod = 1e9 + 7;
long long int MOD = mod;
long long int fact(long long int n);
long long int nCr(long long int n, long long int r) {
  return fact(n) / (fact(r) * fact(n - r));
}
long long int fact(long long int n) {
  int res = 1;
  for (int i = 2; i <= n; i++) res = res * i;
  return res;
}
bool seive(long long int n) {
  long long int prime[n + 1];
  memset(prime, 1, sizeof(prime));
  for (int i = 2; i * i <= n; i++) {
    if (prime[i] == 1) {
      for (int j = i * i; j <= n; j++) {
        prime[i] = 0;
      }
    }
  }
  return prime[n];
}
void re() {
  long long int n, k, d;
  cin >> n >> k >> d;
  vector<long long int> a(n);
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int ans = 0;
  map<long long int, long long int> c;
  for (long long int i = 0; i < d; i++) {
    c[a[i]]++;
  }
  ans = c.size();
  long long int prev = ans;
  for (long long int i = 1; i < n; i++) {
    if (i + (d - 1) < n) {
      c[a[i - 1]]--;
      c[a[i + d - 1]]++;
      long long int h = prev;
      if (c[a[i - 1]] == 0) {
        h--;
      }
      if (c[a[i + d - 1]] == 1 && a[i - 1] != a[i + d - 1]) {
        h++;
      }
      prev = h;
      ans = min(ans, h);
    } else {
      break;
    }
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout.tie(NULL);
  cin.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t--) {
    re();
  }
}
