#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> g(500000);
vector<vector<int>> ver(500000);
vector<int> used(1000001);
vector<int> use(500000);
vector<int> s1(500000);
vector<int> s2(500000);
vector<int> ind1(500000, -1);
vector<int> ind2(500000, -1);
void dfs(int i) {
  int ind;
  used[i] = 1;
  for (int j = 0; j < g[i].size(); j++) {
    ind = g[i][j];
    if (used[ind] == 0) {
      dfs(ind);
      if (s1[ind] + 1 >= s1[i]) {
        s2[i] = s1[i];
        ind2[i] = ind1[i];
        s1[i] = s1[ind] + 1;
        ind1[i] = ind;
      } else if (s1[ind] + 1 >= s2[i]) {
        s2[i] = s1[ind];
        ind2[i] = ind;
      }
    }
  }
}
vector<int> sum(500000);
void f(int i) {
  int ind;
  use[i] = 1;
  for (int j = 0; j < g[i].size(); j++) {
    ind = g[i][j];
    if (use[ind] == 0) {
      if (ind1[i] != ind) {
        sum[ind] = (s1[i] + 1) * (s1[i] + 1);
      } else {
        sum[ind] = (s2[i] + 1) * (s2[i] + 1);
      }
      dfs(ind);
      sum[i] += s1[ind] * s1[ind];
    }
  }
}
vector<int> zfun(string s) {
  int n = (int)s.length();
  vector<int> z(n);
  for (int i = 1, l = 0, r = 0; i < n; ++i) {
    if (i <= r) z[i] = min(r - i + 1, z[i - l]);
    while (i + z[i] < n && s[z[i]] == s[i + z[i]]) ++z[i];
    if (i + z[i] - 1 > r) l = i, r = i + z[i] - 1;
  }
  return z;
}
int main() {
  long long t, n, k, d, sum, y, m, ind;
  cin >> t;
  while (t--) {
    cin >> n >> k >> d;
    vector<long long> x(n);
    for (long long i = 0; i < n; i++) {
      cin >> x[i];
    }
    sum = 0;
    ind = 0;
    m = 10000000;
    long long j = 0;
    for (long long i = 0; i < n; i++) {
      if (used[x[i]] == 0) {
        ind++;
      }
      used[x[i]]++;
      sum++;
      if (sum == d) {
        m = min(m, ind);
        used[x[j]]--;
        sum--;
        if (used[x[j]] == 0) {
          ind--;
        }
        j++;
      }
    }
    cout << m << endl;
    for (int i = 0; i < n; i++) {
      used[x[i]] = 0;
    }
  }
}
