#include <bits/stdc++.h>
using namespace std;
int n, t, k, d, m;
int a[200001], b[1000001];
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> k >> d;
    for (int i = 1; i <= n; i++) cin >> a[i], b[a[i]] = 0;
    int min1;
    int s = 0;
    for (int i = 1; i <= d; i++) {
      if (b[a[i]] == 0) s++;
      b[a[i]]++;
    }
    min1 = s;
    for (int i = 1; i <= n - d; i++) {
      b[a[i]]--;
      if (b[a[i]] == 0) s--;
      if (b[a[i + d]] == 0) s++;
      b[a[i + d]]++;
      min1 = min(min1, s);
    }
    cout << min1 << endl;
  }
  return 0;
}
