#include <bits/stdc++.h>
#pragma GCC optimize("03")
using namespace std;
const long long inf = (long long)1e18;
const int MAXN = (int)1e5;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};
const int N = 100500;
int main() {
  int req;
  scanf("%i", &req);
  while (req--) {
    int n, k, d;
    scanf("%i%i%i", &n, &k, &d);
    vector<int> days(n);
    for (int i = 0; i < n; i++) {
      scanf("%i", &days[i]);
    }
    map<int, int> a;
    for (int i = 0; i < d; i++) {
      a[days[i]] = a[days[i]] + 1;
    }
    int answer = int(1e9);
    answer = min(answer, (int)a.size());
    for (int i = d; i < n; i++) {
      if (a[days[i - d]] == 1) {
        a.erase(days[i - d]);
      } else
        a[days[i - d]]--;
      a[days[i]] = a[days[i]] + 1;
      answer = min(answer, (int)a.size());
    }
    answer = min(answer, (int)a.size());
    printf("%i\n", answer);
  }
}
