#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, k, d;
    cin >> n >> k >> d;
    vector<int> vt(n);
    for (long long i = 0; i < n; i++) cin >> vt[i];
    map<int, int> mp;
    int beg = 0, end = 0;
    int counter = 0;
    int mini = k;
    while (end < n) {
      if (mp[vt[end++]]++ == 0) ++counter;
      while (end - beg > d)
        if (mp[vt[beg++]]-- == 1) --counter;
      if (end - beg == d) mini = min(mini, counter);
    }
    cout << mini << endl;
  }
}
