#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, k, d;
  int dem = 0, a[200005], mi = 1000000, i;
  vector<int> cou;
  for (i = 0; i < 1000003; i++) cou.push_back(0);
  cin >> n >> k >> d;
  t--;
  for (i = 0; i < n; i++) {
    cin >> a[i];
    if (cou[a[i]] == 0) {
      cou[a[i]]++;
      dem++;
    } else
      cou[a[i]]++;
    if (i >= d - 1) {
      mi = min(mi, dem);
      cou[a[i - (d - 1)]]--;
      if (cou[a[i - (d - 1)]] == 0) dem--;
    }
  }
  cout << mi << "\n";
  while (t--) {
    for (i = n - 1; i >= n - d; i--) cou[a[i]] = 0;
    cin >> n >> k >> d;
    dem = 0;
    mi = 1000000;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (cou[a[i]] == 0) {
        cou[a[i]]++;
        dem++;
      } else
        cou[a[i]]++;
      if (i >= d - 1) {
        mi = min(mi, dem);
        cou[a[i - (d - 1)]]--;
        if (cou[a[i - (d - 1)]] == 0) dem--;
      }
    }
    cout << mi << "\n";
  }
}
