#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  long long n, k, d;
  long long t;
  cin >> t;
  for (long long l = 0; l < t; l++) {
    cin >> n >> k >> d;
    long long a[n + 1], pos[k + 1];
    for (long long i = 1; i <= n; i++) {
      cin >> a[i];
      pos[a[i]] = 0;
    }
    long long cnt = 0;
    for (long long i = 1; i <= d; i++) {
      pos[a[i]]++;
      if (pos[a[i]] == 1) cnt++;
    }
    long long mix = cnt;
    for (long long i = d + 1; i <= n; i++) {
      pos[a[i]]++;
      if (pos[a[i]] == 1) {
        cnt++;
      }
      pos[a[i - d]]--;
      if (pos[a[i - d]] == 0) {
        cnt--;
      }
      if (cnt < mix) {
        mix = cnt;
      }
    }
    cout << mix << endl;
  }
}
