#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  int n, k, d;
  cin >> t;
  const int max_n = 1e6;
  int a[max_n];
  int min_cnt = 1e9;
  vector<int> cnt(1e6, 0);
  int cnt_diff = 0;
  for (int j = 0; j < t; j++) {
    cin >> n >> k >> d;
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      cnt[a[i]] = 0;
    }
    cnt_diff = 0;
    for (int i = 0; i < d; i++) {
      if (cnt[a[i]] == 0) {
        cnt_diff++;
      }
      cnt[a[i]] += 1;
    }
    min_cnt = 1e9;
    min_cnt = min(min_cnt, cnt_diff);
    for (int i = d; i < n; i++) {
      cnt[a[i - d]]--;
      if (cnt[a[i - d]] == 0) {
        cnt_diff--;
      }
      if (cnt[a[i]] == 0) {
        cnt_diff++;
      }
      cnt[a[i]]++;
      min_cnt = min(min_cnt, cnt_diff);
    }
    cout << min_cnt << '\n';
  }
  return 0;
}
