#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(nullptr));
const long long INF = 1e18;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n, k, d;
    cin >> n >> k >> d;
    vector<long long> a(n);
    for (long long i = 0; i < n; i++) cin >> a[i];
    set<long long> st;
    vector<long long> cnt(k + 1);
    long long ans = n;
    for (long long i = 0; i < n; i++) {
      cnt[a[i]]++;
      st.insert(a[i]);
      if (i >= d) {
        cnt[a[i - d]]--;
        if (cnt[a[i - d]] == 0) {
          st.erase(a[i - d]);
        }
      }
      if (i >= d - 1) ans = min(ans, (long long)st.size());
    }
    cout << ans << "\n";
  }
  return 0;
}
