#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    long k;
    scanf("%ld", &k);
    int d;
    scanf("%d", &d);
    long arr[n];
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    if (d == 1) {
      cout << 1 << endl;
    } else {
      set<long> con;
      unordered_map<long, int> cnt;
      for (int i = 0; i < d; i++) {
        con.insert(arr[i]);
        cnt[arr[i]]++;
      }
      long ans = con.size();
      long final = con.size();
      if (final == 1) {
        cout << 1 << endl;
      } else {
        for (int i = 0; i < n - d; i++) {
          cnt[arr[i]]--;
          if (cnt[arr[i]] == 0) {
            ans--;
          }
          cnt[arr[i + d]]++;
          if (cnt[arr[i + d]] == 1) {
            ans++;
          }
          final = min(final, ans);
        }
        cout << final << endl;
      }
    }
  }
}
