#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ppi = pair<int, int>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int T;
  cin >> T;
  while (T--) {
    int N, K, D;
    cin >> N >> K >> D;
    vector<int> v(N + 1);
    map<int, int> m;
    for (long long i = 1; i <= N; ++i) {
      cin >> v[i];
      if (i <= D) {
        if (m.find(v[i]) == m.end())
          m.insert({v[i], 1});
        else
          m[v[i]] += 1;
      }
    }
    size_t ans = m.size();
    int l = 1, r = D;
    while (r < N) {
      m[v[l]] -= 1;
      if (m[v[l]] == 0) m.erase(v[l]);
      ++l;
      ++r;
      if (m.find(v[r]) == m.end())
        m.insert({v[r], 1});
      else
        m[v[r]] += 1;
      ans = min(ans, m.size());
    }
    cout << ans << '\n';
  }
  return 0;
}
