#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> genVectorPair(vector<int> v) {
  vector<pair<int, int>> ans;
  for (int i = 0; i < v.size(); i++) {
    ans.push_back(make_pair(v[i], i));
  }
  return ans;
}
long long int power(long long int x, int y, int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int n, int p) { return power(n, p - 2, p); }
long long int nCrmod(long long int n, int r, int p) {
  if (n < r) return 0;
  if (r == 0) return 1;
  long long int fac[n + 1];
  fac[0] = 1;
  for (int i = 1; i <= n; i++) fac[i] = (fac[i - 1] * i) % p;
  return (fac[n] * modInverse(fac[r], p) % p * modInverse(fac[n - r], p) % p) %
         p;
}
long long int nCr(long long int n, long long int r, long long int m) {
  for (int i = 1; i <= r; i++) {
  }
}
long long isPrime(long long int n) {
  if (n == 1) return false;
  if (n == 2 || n == 3) return true;
  if (n % 2 == 0) return false;
  for (int i = 3; i <= sqrt(n); i += 2) {
    if (n % i == 0) return false;
  }
  return true;
}
int modFact(int n, int p) {
  if (n >= p) return 0;
  int result = 1;
  for (int i = 1; i <= n; i++) result = (result * i) % p;
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int queries;
  cin >> queries;
  for (long long int itr = 0; itr < queries; itr++) {
    long long int n, k, d;
    cin >> n >> k >> d;
    int a[n];
    map<int, int> m;
    for (int i = 0; i < d; i++) {
      cin >> a[i];
      if (m.find(a[i]) == m.end()) {
        m[a[i]] = 1;
      } else {
        m[a[i]]++;
      }
    }
    int ans = m.size();
    for (int i = d; i < n; i++) {
      cin >> a[i];
      if (m.find(a[i]) == m.end()) {
        m[a[i]] = 1;
      } else {
        m[a[i]]++;
      }
      if (m[a[i - d]] == 1) {
        m.erase(a[i - d]);
      } else {
        m[a[i - d]]--;
      }
      ans = min(ans, (int)m.size());
    }
    cout << ans << endl;
  }
}
