#include <bits/stdc++.h>
using namespace std;
const long long inf = 10000000;
vector<long long> t;
int main() {
  int t;
  cin >> t;
  for (int q = 0; q < t; q++) {
    long long n, k, d;
    cin >> n >> k >> d;
    vector<pair<int, int>> a;
    long long old_x = 0, x;
    for (int i = 0; i < n; i++) {
      cin >> x;
      if (old_x == x) {
        a[a.size() - 1].first++;
      } else {
        a.push_back({1, x});
      }
      old_x = x;
    }
    long long min_j = inf;
    map<int, int> j;
    long long t_sum = 0, back = 0;
    for (int i = 0; i < a.size() + 1; i++) {
      if (t_sum < d && i < a.size()) {
        t_sum += a[i].first;
        if (j.find(a[i].second) != j.end()) {
          j[a[i].second]++;
        } else {
          j[a[i].second] = 1;
        }
        while (t_sum >= d) {
          min_j = min(min_j, (long long)j.size());
          t_sum -= a[back].first;
          j[a[back].second]--;
          if (j[a[back].second] == 0) {
            j.erase(a[back].second);
          }
          back++;
        }
      }
    }
    if (min_j != inf)
      cout << min_j << endl;
    else
      cout << j.size() << endl;
  }
}
