#include <bits/stdc++.h>
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int INF = 1000000000;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int q;
  cin >> q;
  for (int iii = 0; iii < q; ++iii) {
    int n, k, d;
    cin >> n >> k >> d;
    vector<int> ar(n);
    for (int i = 0; i < n; ++i) cin >> ar[i];
    map<int, int> m;
    int cnt = 0;
    for (int i = 0; i < d; ++i) {
      m[ar[i]]++;
      if (m[ar[i]] == 1) cnt++;
    }
    int mn = cnt;
    for (int i = d; i < n; ++i) {
      m[ar[i]]++;
      if (m[ar[i]] == 1) cnt++;
      m[ar[i - d]]--;
      if (m[ar[i - d]] == 0) cnt--;
      mn = min(mn, cnt);
    }
    cout << mn << endl;
  }
  return 0;
}
