#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  vector<int> answers(q);
  for (int i = 0; i < q; ++i) {
    int n, k, d;
    cin >> n >> k >> d;
    vector<int> a(n);
    map<int, int> m;
    int cnt = 0;
    int ans = d;
    for (int j = 0; j < n; j++) {
      cin >> a[j];
      if (m[a[j]] == 0) {
        cnt++;
      }
      m[a[j]]++;
      if (j == d - 1) {
        ans = min(ans, cnt);
      }
      if (j >= d) {
        m[a[j - d]]--;
        if (m[a[j - d]] == 0) {
          cnt--;
        }
        ans = min(ans, cnt);
      }
    }
    ans = min(ans, cnt);
    answers[i] = ans;
  }
  for (int i = 0; i < q; ++i) {
    cout << answers[i] << endl;
  }
}
