#include <bits/stdc++.h>
using namespace std;
int middle(int a, int b, int c) {
  if ((a <= b && b <= c) || (c <= b && b <= a))
    return b;
  else if ((b <= a && a <= c) || (c <= a && a <= b))
    return a;
  else
    return c;
}
template <typename KeyType, typename ValueType>
std::pair<KeyType, ValueType> get_max(const std::map<KeyType, ValueType> &x) {
  using pairtype = std::pair<KeyType, ValueType>;
  return *std::max_element(x.begin(), x.end(),
                           [](const pairtype &p1, const pairtype &p2) {
                             return p1.second < p2.second;
                           });
}
static inline bool isvowel(char ch) {
  static const std::string vowels("aeiouEAIOU");
  return vowels.end() != std::find(vowels.begin(), vowels.end(), ch);
}
template <typename Map>
bool map_compare(Map const &lhs, Map const &rhs) {
  return lhs.size() == rhs.size() &&
         std::equal(lhs.begin(), lhs.end(), rhs.begin());
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k, d, x, cnt = 0, m;
    cin >> n >> k >> d;
    deque<int> dq;
    map<int, int> make_pair;
    for (int i = 0; i < n; ++i) {
      cin >> x;
      if (dq.size() < d) {
        dq.push_back(x);
        if (make_pair[x] == 0) {
          cnt++;
        }
        make_pair[x]++;
        m = cnt;
      } else {
        if (make_pair[dq.front()] == 1) cnt--;
        make_pair[dq.front()]--;
        dq.pop_front();
        dq.push_back(x);
        if (make_pair[x] == 0) cnt++;
        make_pair[x]++;
        m = min(cnt, m);
      }
    }
    cout << m << endl;
  }
  return 0;
}
