#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
void Compute(long long int n, long long int k, long long int d) {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  vector<long long int> v(n);
  for (long long int i = 0; i < n; i++) cin >> v[i];
  vector<bool> vec(k + 1, false);
  map<long long int, long long int> mp;
  long long int min = k;
  long long int i = 0, j = d - 1;
  long long int c = 0;
  for (long long int p = i; p <= j; p++) {
    mp[v[p]]++;
    if (!vec[v[p]]) {
      vec[v[p]] = true;
      c++;
    }
  }
  if (c < min) min = c;
  while (j < (n - 1)) {
    mp[v[i]]--;
    if (mp[v[i]] == 0) {
      vec[v[i]] = false;
      c--;
    }
    i++;
    j++;
    mp[v[j]]++;
    if (!vec[v[j]]) {
      vec[v[j]] = true;
      c++;
    }
    if (c < min) min = c;
  }
  if (c < min) min = c;
  cout << min << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t;
  long long int n, k, d;
  cin >> t;
  while (t--) {
    cin >> n >> k >> d;
    Compute(n, k, d);
  }
}
