#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 50;
int vis[MAXN], a[MAXN];
inline int read() {
  int res = 0, f = 1;
  char ch;
  ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    res = (res << 3) + (res << 1) + ch - 48;
    ch = getchar();
  }
  return f * res;
}
int main() {
  int times;
  times = read();
  while (times--) {
    int n, k, d;
    n = read(), k = read(), d = read();
    for (int i = 1; i <= n; i++) {
      a[i] = read();
    }
    int now = 0, minn;
    for (int i = 1; i <= d; i++) {
      if (!vis[a[i]]) now++;
      vis[a[i]]++;
    }
    minn = now;
    for (int i = d + 1; i <= n; i++) {
      if (!vis[a[i]]) now++;
      vis[a[i]]++;
      if (vis[a[i - d]] == 1) now--;
      vis[a[i - d]]--;
      minn = min(minn, now);
    }
    for (int i = n - d + 1; i <= n; i++) vis[a[i]] = 0;
    printf("%d\n", minn);
  }
  return 0;
}
