#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  int n, k, d, v, col, ans;
  queue<int> q;
  vector<int> mas;
  for (int j = 0; j < t; j++) {
    while (!q.empty()) {
      q.pop();
    }
    col = 0;
    ans = 0;
    cin >> n >> k >> d;
    mas.resize(k);
    for (int& p : mas) {
      p = 0;
    }
    for (int i = 0; i < d; i++) {
      cin >> v;
      q.push(--v);
      if (mas[v] == 0) {
        col++;
      }
      mas[v]++;
    }
    ans = col;
    for (int i = d; i < n; i++) {
      v = q.front();
      q.pop();
      if (mas[v] == 1) {
        col--;
      }
      mas[v]--;
      cin >> v;
      q.push(--v);
      if (mas[v] == 0) {
        col++;
      }
      mas[v]++;
      ans = min(ans, col);
    }
    cout << ans << endl;
  }
  return 0;
}
