#include <bits/stdc++.h>
using namespace std;
int fr[1000005], a[1000005];
int main() {
  int t, n, k, d, l, i;
  int ans = 0, m;
  cin >> t;
  while (t--) {
    memset(fr, 0, sizeof(fr));
    memset(a, 0, sizeof(a));
    ans = 0;
    l = 0;
    cin >> n >> k >> d;
    for (i = 0; i < n; i++) {
      cin >> a[i];
      if (i < d) {
        if (fr[a[i]] == 0) ans++;
        fr[a[i]]++;
        m = ans;
        continue;
      }
      if (a[l] != a[i]) {
        if (fr[a[l]] == 1) m--;
        if (!fr[a[i]]) m++;
        fr[a[i]]++;
        fr[a[l]]--;
        ans = min(m, ans);
      }
      l++;
    }
    cout << ans << endl;
  }
  return 0;
}
