#include <bits/stdc++.h>
using namespace std;
int greater_than(long long arr[], int n, long long x) {
  int l = 0, r = n - 1, ans = -1;
  while (l <= r) {
    int mid = l + (r - l) / 2;
    if (arr[mid] == x) return mid;
    if (arr[mid] < x) l = mid + 1;
    if (arr[mid] > x) {
      ans = mid;
      r = mid - 1;
    }
  }
  return ans;
}
long long floorSqrt(long long x) {
  if (x == 0 || x == 1) return x;
  unsigned long long start = 1, end = x, ans;
  while (start <= end) {
    unsigned long long mid = start + (end - start) / 2;
    if (mid * mid == x) return mid;
    if (mid * mid < x) {
      start = mid + 1;
      ans = mid;
    } else
      end = mid - 1;
  }
  return ans;
}
long long power(int base, int exp) {
  long long res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) res = (res * base) % 1000000007;
    ;
    base = (base * base) % 1000000007;
    ;
    exp /= 2;
  }
  return res % 1000000007;
  ;
}
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, k, d;
    cin >> n >> k >> d;
    int arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    map<int, int> m;
    for (int t = 0; t < d; t++) {
      m[arr[t]]++;
    }
    int i = 1, j = d, req = m.size(), temp = m.size();
    while (i < n && j < n) {
      m[arr[i - 1]]--;
      m[arr[j]]++;
      if (arr[i - 1] != arr[j]) {
        if (m[arr[i - 1]] > 0 && m[arr[j]] == 1)
          temp++;
        else if (m[arr[i - 1]] <= 0 && m[arr[j]] > 1)
          temp--;
      }
      if (temp < req) req = temp;
      i++;
      j++;
    }
    d == 1 ? cout << "1\n" : cout << req << "\n";
  }
}
