#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18 + 1;
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 100;
const long double EPS = 1e-12;
const long double PI = acos(-1);
const long long XX[] = {0, -1, 0, 1, 0, -1};
const long long YY[] = {-1, 0, 1, 0, -1, 0};
const long long ALPH = 31;
void bye() {
  cout << "\n";
  exit(0);
}
long long cnt[MAXN];
void solve() {
  long long n, k, d;
  cin >> n >> k >> d;
  vector<long long> g(n);
  for (long long i = 0; i < n; i++) {
    cin >> g[i];
  }
  long long res = 0;
  for (long long i = 0; i < d; i++) {
    if (!cnt[g[i]]) {
      res++;
    }
    cnt[g[i]]++;
  }
  long long ans = res;
  for (long long i = d; i < n; i++) {
    cnt[g[i - d]]--;
    if (!cnt[g[i - d]]) {
      res--;
    }
    if (!cnt[g[i]]) {
      res++;
    }
    cnt[g[i]]++;
    ans = min(ans, res);
  }
  for (auto v : g) {
    cnt[v] = 0;
  }
  cout << ans << "\n";
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long TEST_COUNT = 1;
  cin >> TEST_COUNT;
  while (TEST_COUNT--) {
    solve();
  }
  bye();
}
