#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long gcd(long long a, long long b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
inline void take_input(long long A[], long long n) {
  for (long long i = 0; i < n; i++) {
    cin >> A[i];
  }
}
inline void show(long long A[], long long n) {
  for (long long i = 0; i < n; i++) {
    cout << A[i] << " ";
  }
  cout << '\n';
}
inline void show_vect(vector<long long> v) {
  for (long long i = 0; i < v.size(); i++) {
    cout << v[i] << " ";
  }
  cout << '\n';
}
inline long long countDivisibles(long long a, long long b, long long c) {
  if (a % c == 0) {
    return (a % c + b % c + 1);
  }
  return (a % c + b % c);
}
inline bool sortbysec(const pair<long long, long long> &a,
                      const pair<long long, long long> &b) {
  return (a.second < b.second);
}
inline bool sortbysecdesc(const pair<long long, long long> &a,
                          const pair<long long, long long> &b) {
  return (a.second > b.second);
}
inline void swap(long long &a, long long &b) {
  long long temp = a;
  a = b;
  b = temp;
}
inline void initialise(long long A[], long long n, long long k) {
  for (long long i = 0; i < n; i++) {
    A[i] = k;
  }
}
inline void vect_input(vector<long long> &v, long long n) {
  for (long long i = 0; i < n; i++) {
    long long input;
    cin >> input;
    v.push_back(input);
  }
}
void p_g_t() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
bool isprime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int32_t main() {
  p_g_t();
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, d;
    cin >> n >> k >> d;
    long long *arr = new long long[n];
    ;
    take_input(arr, n);
    unordered_map<long long, long long> freq;
    long long distinct = 0;
    vector<long long> ans;
    for (long long i = 0; i < n; i++) {
      if (i >= d) {
        freq[arr[i - d]]--;
        if (freq[arr[i - d]] == 0) {
          distinct--;
        }
      }
      freq[arr[i]]++;
      if (freq[arr[i]] == 1) {
        distinct++;
      }
      if (i >= d - 1) {
        ans.push_back(distinct);
      }
    }
    long long answer = *min_element(ans.begin(), ans.end());
    cout << answer << '\n';
  }
}
