#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int64_t t;
  cin >> t;
  while (t--) {
    int64_t n, k, d;
    cin >> n >> k >> d;
    int64_t a[n];
    for (int64_t i = 0; i < n; i++) {
      cin >> a[i];
    }
    int64_t uni = 0;
    int64_t mina = 1e9;
    map<int64_t, int64_t> mp;
    for (int64_t i = 0; i < d; ++i) {
      mp[a[i]]++;
    }
    mina = mp.size();
    int64_t temp = 0;
    {
      for (int64_t i = 1; i + d - 1 < n; i++) {
        mp[a[i - 1]]--;
        if (mp[a[i - 1]] == 0) mp.erase(a[i - 1]);
        mp[a[i + d - 1]]++;
        temp = mp.size();
        mina = min(mina, temp);
      }
      cout << mina << endl;
    }
  }
}
