#include <bits/stdc++.h>
using namespace std;
int const maxn = 2e5 + 5, maxm = 1e6 + 5;
int a[maxn], cnt[maxm], sum, ans;
int main() {
  int T, n, k, d;
  cin >> T;
  while (T--) {
    cin >> n >> k >> d;
    ans = 0;
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= d; i++) {
      if (cnt[a[i]] == 0) ans++;
      cnt[a[i]]++;
    }
    sum = ans;
    for (int i = d + 1; i <= n; i++) {
      if (cnt[a[i]] == 0) sum++;
      cnt[a[i]]++;
      if (cnt[a[i - d]] == 1) sum--;
      cnt[a[i - d]]--;
      ans = min(ans, sum);
    }
    cout << ans << endl;
  }
  return 0;
}
