#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int inf = 1e9;
const long double eps = 1e-7;
const long double pi = acos(-1);
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};
const int mod1 = 998244353;
const int mod2 = 1e9 + 7;
const int N = 2e5 + 11;
const int M = 1e6 + 11;
int a[N];
int cnt[M];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k, d;
    cin >> n >> k >> d;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
    }
    int val = 0;
    for (int i = 1; i <= d; i++) {
      cnt[a[i]]++;
      if (cnt[a[i]] == 1) val++;
    }
    int ans = val;
    for (int i = d + 1; i <= n; i++) {
      cnt[a[i - d]]--;
      if (cnt[a[i - d]] == 0) val--;
      cnt[a[i]]++;
      if (cnt[a[i]] == 1) val++;
      ans = min(ans, val);
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) cnt[a[i]] = 0;
  }
  return 0;
}
