The only difference between easy and hard versions is constraints.The BerTV channel every day broadcasts one episode of one of the $$$k$$$ TV shows. You know the schedule for the next $$$n$$$ days: a sequence of integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the show, the episode of which will be shown in $$$i$$$-th day.The subscription to the show is bought for the entire show (i.e. for all its episodes), for each show the subscription is bought separately.How many minimum subscriptions do you need to buy in order to have the opportunity to watch episodes of purchased shows $$$d$$$ ($$$1 \le d \le n$$$) days in a row? In other words, you want to buy the minimum number of TV shows so that there is some segment of $$$d$$$ consecutive days in which all episodes belong to the purchased shows.

The first line contains an integer $$$t$$$ ($$$1 \le t \le 100$$$) — the number of test cases in the input. Then $$$t$$$ test case descriptions follow. The first line of each test case contains three integers $$$n, k$$$ and $$$d$$$ ($$$1 \le n \le 100$$$, $$$1 \le k \le 100$$$, $$$1 \le d \le n$$$). The second line contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le k$$$), where $$$a_i$$$ is the show that is broadcasted on the $$$i$$$-th day. It is guaranteed that the sum of the values of $$$n$$$ for all test cases in the input does not exceed $$$100$$$.

Print $$$t$$$ integers — the answers to the test cases in the input in the order they follow. The answer to a test case is the minimum number of TV shows for which you need to purchase a subscription so that you can watch episodes of the purchased TV shows on BerTV for $$$d$$$ consecutive days. Please note that it is permissible that you will be able to watch more than $$$d$$$ days in a row.

NoteIn the first test case to have an opportunity to watch shows for two consecutive days, you need to buy a subscription on show $$$1$$$ and on show $$$2$$$. So the answer is two.In the second test case, you can buy a subscription to any show because for each show you can find a segment of three consecutive days, consisting only of episodes of this show.In the third test case in the unique segment of four days, you have four different shows, so you need to buy a subscription to all these four shows.In the fourth test case, you can buy subscriptions to shows $$$3,5,7,8,9$$$, and you will be able to watch shows for the last eight days.

#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define IO std::ios::sync_with_stdio(false);cin.tie(0)
#define endl '\n'
using namespace std;
const double pi = 3.141592653589793238462;
const int maxn = 1e6+5;
const double eps = 1e-18;
const ull base  = 13331;
const ll mod = 1e9+7;

int a[maxn];
map<ll,ll> ff;

int main(){
    IO;
    int t;
    int n,k,d;
    cin>>t;
    while(t--){
        cin>>n>>k>>d;
        int ans = 0;
        ff.clear();
        for(int i=0;i<n;i++){
            cin>>a[i];
            if(ff[a[i]]==0&&i<d){
                ans++;
            }
            if(i<d)ff[a[i]]++;

        }
        //int ans = 0;
        int tmp = ans;
        for(int i=1,j=d;j<n;i++,j++){
            if(ff[a[i-1]]-1==0){
                tmp--;
            }
            ff[a[i-1]]--;
            if(ff[a[j]]==0){
                tmp++;
            }
            ff[a[j]]++;
            ans = min(ans,tmp);
        }
        cout<<ans<<endl;
    }
}

#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define lli int
#define loop(i,x,n) for(lli i=x;i<n;i++)
#define loopr(i,x,n) for(lli i=n-1;i>=x;i--)
#define time ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.setf(ios::showpoint);
#define test lli t; cin>>t; while(t--)
#define mod 1000000007
using namespace std;
int main()
{
    time
    test
    {
        lli n,k,q;
        cin>>n>>k>>q;
        unordered_map<lli,lli> b;
        lli a[n],j=0,ans=0;
        set<lli> s;
        loop(i,0,n)
        {
            cin>>a[i];
            b[a[i]]++;
            s.insert(a[i]);
            if(i==(q-1)) ans=s.size();
            if(i>=q)
            {
                b[a[j]]--;
                if(!b[a[j]]) s.erase(a[j]);
                ans=min(ans,(lli)s.size());
                j++;
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <stack>
#include <string>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    vector <int> fin(1000002);
    int t;
    cin >> t;
    for(int ct = 0;ct<t;++ct){
        int n,k,d;
        cin >> n >> k >> d;
        vector <int> a(n);
        for(int i = 0;i<n;++i){
            cin >> a[i];
        }
        if(d==1){
            cout << 1 << endl;
        }
        else{
            int cnt = 0;
            for(int i = 0;i<d;++i){
                if(fin[a[i]]==0){
                    cnt++;
                }
                fin[a[i]]++;
            }
            int ans = cnt;
            for(int i = d;i<n;++i){
                if(fin[a[i-d]]==1){
                    cnt--;
                }
                fin[a[i-d]]--;
                if(fin[a[i]]==0){
                    cnt++;
                }
                fin[a[i]]++;
                ans = min(ans,cnt);
            }
            cout << ans << endl;
            for(int i = 0;i<n;++i){
                fin[a[i]] = 0;
            }
        }
    }
    return 0;
}

#pragma GCC optimize("-O3")
/*
				C++
				encoding: UTF-8
				Last Modified: 29/Oct/19 01:06:30 PM
*/

#include <bits/stdc++.h>
#ifdef H4wk3ye
#	include <prettypr.hpp>
#endif

using namespace std;

// clang-format off

//#define		int             long long
#define		ve                     vector
#define		pb                     push_back
#define		endl                   "\n"
#define		ff                     first
#define		ss                     second
#define		pii                    pair<int, int>
#define		len(v)                 (int)v.size()
#define		all(v)                 v.begin(), v.end()
#define		reset(a, b)            memset(a, b, sizeof(a));
#define		fr(i, s, n)            for (int i = s ; i < n ; ++i)
#define		dfr(i, s, n)           for (int i = s ; i > n ; --i)

template < typename T > void pr (const T& t) {
	cout << t << "\n";
}

template < typename T, typename U, typename... ARGS >
void pr (const T& t, const U& u, const ARGS&... args) {
	cout << t << " ";
	pr (u, args...);
}

// clang-format on

int has[1000001];
signed main () {
	ios_base::sync_with_stdio (false), cin.tie (nullptr), cout.tie (nullptr);
	int T;
	cin >> T;
	while (T--) {
		int n, k, d, x;
		cin >> n >> k >> d;
		int a[n], ans = n + 1;
		fr (i, 0, n) cin >> a[i];
		int p = 0;
		fr (i, 0, 1000001) has[i] = 0;
		for (int i = 0; i < d; i++) {
			if (has[a[i]] == 0) p++;
			has[a[i]]++;
		}
		ans = p;
		for (int i = d; i < n; i++) {
			has[a[i - d]]--;
			if (!has[a[i - d]]) p--;
			if (has[a[i]] == 0) p++;
			has[a[i]]++;
			ans = min (ans, p);
		}
		cout << ans << endl;
	}
	return 0;
}

 #include "bits/stdc++.h"
using namespace std;

void solve() {

	int n, k, d;
	cin >> n >> k >> d;
	int arr[n];
	for (int i=0; i<n; i++) cin >> arr[i];

	map<int, int> occ;
	int dist = 0;
	for (int i=0; i<d; i++) {
		if (occ[arr[i]] == 0) dist++;
		occ[arr[i]]++;
	}
	int mn = dist;
	for (int i=d; i<n; i++) {
		int lef = arr[i-d];
		if (occ[lef] == 1) dist--;
		occ[lef]--;
		if (occ[arr[i]] == 0) dist++;
		occ[arr[i]]++;
		mn = min(mn, dist);
	}
	cout << mn << endl;

}

int main() {

	int t;
	cin >> t;
	while (t--) solve();

}

#include <bits/stdc++.h>
using namespace std;
typedef long long int l1;
typedef vector <int> vi;
typedef vector <long long int> v1;
#define pb push_back
#define mp make_pair
#define iter(i,a,b) for(i=a;i<b;i++)

l1 bin(v1 vec, l1 l, l1 r, l1 x)
{

    if (r >= l) {
        l1 mid = l + (r - l) / 2;
 		if (vec[mid] == x)
            return mid;
        if (vec[mid] > x)
            return bin(vec, l, mid - 1, x);
        return bin(vec, mid + 1, r, x);
    }
    return -1;
    //index of first equal element returned;
    //works only on sorted vector
}

int main()
{
    ios_base::sync_with_stdio(false);      //for fast cin and cout streams
    cin.tie(NULL);
    cout.tie(NULL);

    //THINK..THINK..THINK..nope..EVEN THOSE CORNER CASES
    //DONE ??..NO.!...GO BACK AGAIN NOW..dumbass
    //ALL RIGHT..GOOD TO GO..
    //MAKE IT SYNTACTICALLY CORRECT..though

 int t;
 cin>>t;
 while(t--)
 {
     int n,k,d;
     cin>>n>>k>>d;
     int i,j;
     set<int> st;
     vi vec(n);
     iter(i,0,n)
     cin>>vec[i];
     int mn=10e6;
     for(i=0;i<=(n-d+1);i++)
     {
         j=i;
         while((j-i)<d)
         {
             st.insert(vec[j]);
             j++;
         }

         int len=st.size();
         mn=min(mn,len);
         st.clear();
     }

     cout<<mn<<"\n";

 }

return 0;
}

#include <bits/stdc++.h>
#include <algorithm>

#define N 100010
#define pb push_back
#define fi first
#define se second
#define si size()
#define ll long long
#define mp make_pair
#define iter ::iterator
#define all(v) v.begin(), v.end()
#define READ(f) freopen (f, "r", stdin)
#define WRITE(f) freopen (f, "w", stdout)
#define pp pop_back
#define mapiter map<int, int>::iterator
#define pii pair<int, int>
#define forn(i, n) for(int i = 0; i < n; ++i)
#define forn1(i, n) for(int i = 0; i <= n; ++i)
#define forr(i, x, n) for(int i = x; i <= n; ++i)
#define r0 return 0

const int inf = 1e9 + 1;
const int modw = 1e9 + 7;

using namespace std;

int a[N * 2];

int main()
{
	int tt;
	cin >> tt;
	forn(ii, tt)
	{
		int n, k, d;
		int b[N * 10] = {0};
		cin >> n >> k >> d;
		int ss = 0;
		forn(i, n)
		{
			cin >> a[i];
			if(i < d)
			{
    			if(b[a[i]] == 0)	ss++;
    			b[a[i]]++;
			}
		}
		int ans = ss;
		for(int i = d; i < n; i++)
		{
			b[a[i - d]]--;
			if(b[a[i - d]] == 0)	ss--;
			if(b[a[i]] == 0)	ss++;
			b[a[i]]++;
			ans = min(ans, ss);
		}
		cout << ans << endl;
	}
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

int main()
{
    int t;
    cin >> t;

    while (t--) {
        int n, k, d;
        cin >> n  >> k >> d;

        int a[n];
        set<int> st;

        for (int i = 0; i < n; i++) {
            cin >> a[i];
            if (i < d) st.insert(a[i]);
        }

        int mn = st.size();

        for (int i = 1; i+d < n+1; i++) {

            st.clear();

            for (int j = i; j < i+d; j++) st.insert(a[j]);

            int x = st.size();

            //cout << i << ' ' << x << endl;

            mn = min(mn, x);
        }

        cout << mn << endl;

    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#include <string>
#include <vector>
#define ll           long long
#define vint         vector<int>
#define vll          vector<ll>
#define pr           pair<int,int>
#define mpr(a,b)     make_pair(a,b)
#define si(a)        scanf("%d",&a)
#define sc(a)        scanf("%c",&a)
#define sii(a,b)     scanf("%d %d",&a,&b)
#define siii(a,b,c)  scanf("%d %d %d", &a, &b,&c)
#define sl(a)        scanf("%lld",&a)
#define sll(a,b)     scanf("%lld %lld",&a, &b)
#define slll(a,b,c)  scanf("%lld %lld %lld",&a, &b, &c)
#define sqr(a)       a*a;
#define pf           printf
#define pb           push_back
#define pfi(a)       printf("%d\n",a)
#define pfis(a)      printf("%d ",a)
#define pfii(a,b)    printf("%d %d\n",a,b)
#define pfiii(a,b,c) printf("%d %d %d\n",a,b,c)
#define pfl(a)       printf("%lld\n",a);
#define pfll(a,b)    printf("%lld %lld\n",a,b)
#define pflll(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define mem(a,b)     memset(a, b, sizeof(a));
#define max3(a,b,c)  max(max(a, b), c);
#define min3(a,b,c)  min(min(a, b), c);
#define for0(i,n)    for(int i = 0; i < n;  i++)
#define for1(i,n)    for(int i = 1; i <= n;  i++)
#define rfor0(i,n)   for(int i = n - 1; i>=0; i--)
#define rfor1(i,n)   for(int i = n; i>=1, i--)
#define pi           acos(-1.0)
#define in           freopen("input.txt", "r", stdin);
#define out          freopen("output.txt", "w", stdout);
#define cs(t)        printf("Case %d:",++t);
#define mp           make_pair
#define all(str)     str.begin(),str.end()
#define X            first
#define Y            second
#define re           register int
#define ak           *
#define err          1e-5
#define pi           acos(-1.0)
const int maxn = 2e5+ 7;
int  sum, sum1, cnt, ans, flag, maxi = -1, mini = INT_MAX, len;
int num[maxn], m = 1, t;

int main()
{
    int tc;
    cin>> tc;
    while(tc--)
    {
        map<int, int> mark;
        int n, k, d;
        cin >> n >> k >> d;
        int a[n];
        for0(i, n) cin >> a[i];
        for0(i, d)
        {
            if(mark[a[i]] == 0) cnt++;
            mark[a[i]]++;
        }
        ans = cnt;
        for(int i = d; i < n; i++)
        {
            if(mark[a[i - d]] == 1) cnt--;
             mark[a[i- d]]--;
            if(mark[a[i]] == 0) cnt++;
            mark[a[i]]++;
            ans = min(ans, cnt);

        }
        cout << ans << endl;
        ans = cnt = 0;
    }
}

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define M 1000000007
#define ll long long int
#define F first
#define S second
#define INF (int)1000000000
const int N = 1e6;
#define maax(a,b,c) max((int)a,max((int)b,(int)c))
#define miin(a,b,c) min((int)a,min((int)b,(int)c))
#define mp make_pair
#define int long long int
#define all(a) a.begin(),a.end()
#define I insert
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define inf (long long) 1e18
#define vl vector<ll>
#define sz(a) (ll)a.size()
#define mem(a,b) memset(a,b,a.size())
#define fr(i,m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define fre(i,m, n) for (int i = (int)(n); i <= (int)(m); i--)
#define rall(x) (x).rbegin(), (x).rend()
#define TIME    cerr << "\nTime elapsed: " << setprecision(5) <<1000.0 * clock() / CLOCKS_PER_SEC << "ms\n";

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(int x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
typedef long long LL;
typedef pair<int, int> PII;
map<char,int>m;
int fuck(int x,int y)
{
	int a,b;cin>>a>>b;
	if(x!=a)
	{
		if(((a<x) && (m['L']<(x-a))) || ((a>=x) && (m['R']<(a-x))))
		{
			cout<<"NO\n";return 0;
		}
	}
	if(y!=b)
	{
		if(((b<y) && (m['D']<(y-b))) || ((b>=y) && m['U']<(b-y)))
		{
			cout<<"NO\n";return 0;
		}
	}int h,g;
	if((a>0 && x>0) || (a<0 && x<0)) h=abs(abs(a)-abs(x));
	else h=abs(a)+abs(x);
	if((b>0 && y>0) || (b<0 && y<0)) g=abs(abs(b)-abs(y));
	else g=abs(b)+abs(y);
	cout<<"YES "<<h+g<<"\n";
	return 0;
}

int solve()
{
    int n,k,d;cin>>n>>k>>d;int u=0;
    vector<int>a(n);fr(i,0,n) cin>>a[i];map<int,int>freq;
    if(n==1 || k==1 || d==1)
    {
    	cout<<1<<"\n";return 0;
	}
    fr(i,0,d)
    {
    	freq[a[i]]++;
    	if(freq[a[i]]==1) u++;
		//debug(freq,a[i],u);
	}
	int l=0,r=d,ans=u;
	while(r<n)
	{
		//debug(freq,a[r],a[l]);
		freq[a[l]]--;
		if(freq[a[l]]==0) u--;freq[a[r]]++;if(freq[a[r]]==1) u++;
		//debug(u,freq);
		ans=min(ans,u);
		l++;r++;
	}cout<<ans<<"\n";
	return 0;
}
int32_t main()
{
	ios::sync_with_stdio(0); cin.tie(0);
    int t;cin>>t;
    while(t--) solve();
	return 0;
}

//std::fill to fill a vector fill(all(a),0);
//1 2 3 4 5 10 11 3 6 16
//1 2 3 3 4 5 6 10 11 16
//319-207=112+50=172
//set-> all elements are unique and sorted *_*�1212

// by VIDIT BHARDWAJ
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;

// when we want to insert same element multiple times into pbds
// typedef tree<pair<int,int>,null_type,less<pair<int,int > >,rb_tree_tag,tree_order_statistics_node_update> pbds;

#define int                     long long int
#define pb                      push_back
#define mk(arr,n,type)          type *arr=new type[n]; //mk(pos,n,vector<int>)
#define setbits(x)              __builtin_popcountll(x)
#define zerobits(x)             __builtin_ctzll(x)
#define ps(x,y)                 fixed<<setprecision(y)<<x // cout<<ps(1.255114,4)
#define tc(t)                   int t; cin>>t; while(t--)

const long long mod=1000000007;
const int inf=1000000000000000000;
const long double pi = 3.14159265358979323846264338;

bool double_compare(double a, double b, double epsilon = 0.001)
{
    return std::abs(a - b) < epsilon;
}
int lcm(int a,int b){
    return (a*b)/__gcd(a,b);
}
bool isPrime(int n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;

    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (int i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0)
            return false;
    }

    return true;
}
// Fermat's little theorem
int pow(int a, unsigned int b,int mod1){

    int ans=1;
    while(b){

        if(b&1ll){

            ans*=a;
            ans%=mod1;
        }
        b/=2;
        a*=a;
        a%=mod1;
    }

    return ans;
}
int inverse(int a,int mod1){

    return pow(a,mod1-2,mod1);    // a^-1%p
}
///////////////////////////////////////////////////////////////////////////////////////////////////

signed main()
{
    tc(t){

        int n,k,days;
        cin>>n>>k>>days;

        int a[n+1];
        for(int i=0;i<n;i++){
            cin>>a[i];
        }

        map<int,int> freq;
        for(int i=0;i<days;i++){
            freq[a[i]]++;
        }

        int ans=freq.size();
        for(int i=days;i<n;i++){

            freq[a[i-days]]--;
            freq[a[i]]++;

            if(freq[a[i-days]]==0){
                freq.erase(a[i-days]);
            }

            int x=freq.size();
            ans=min(ans,x);
        }

        cout<<ans<<endl;
    }

    return 0;
}

/*

*/

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>

using namespace std;

int main() {
	int tt;
	cin >> tt;
	for (int i = 0; i < tt; i++) {
		int m, k, d;
		cin >> m >> k >> d;
		vector<int> v(m);
		for (int j = 0; j < m; j++) {
			cin >> v[j];
		}
		int l = 0, r = d;
		int mx = 10000000;
		while (r <= m) {
			set<int> s;
			for (int j = l; j < r; j++) {
				s.insert(v[j]);
			}
			mx = min(mx, int(s.size()));
			l++; r++;
		}
		cout << mx << endl;
	}
	//system("pause");
	return 0;
}

/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout);
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

int m[1000001];
void solve()
{
	ll n,k,d;
	cin>>n>>k>>d;

	ll a[n],i;

	rep(i,n) cin>>a[i];
	memset(m,0,sizeof(m));
	ll cnt=0;
	rep(i,d)
	{
		m[a[i]]++;
		if(m[a[i]]==1)
			cnt++;
	}

	ll ans=cnt;
	for(i=d;i<n;i++)
	{
		if(a[i]==a[i-d])
			continue;
		m[a[i]]++;
		if(m[a[i]]==1)
			cnt++;
		m[a[i-d]]--;
		if(m[a[i-d]]==0)
			cnt--;
		ans=min(ans,cnt);
	}
	cout<<ans<<"\n";
}
int main()
{
	fio();
	fast
	ll t=1;
	cin>>t;

	while(t--){
		solve();
	}
	return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define forn(i,a,b) for(long long i = a; i < b; i++)
#define pb push_back
#define ins insert
#define pr pair<int,int>
#define fr first
#define sc second
#define boost ios_base::sync_with_stdio(false); cin.tie(0);
typedef long long ll;

void print(vector<ll> v) {
    for(auto x : v) cout << x << " ";
    cout << endl;
}

const int mod = 1000000007;
const int inf = (int)1e9+5;

int main()
{
    int t;
    cin >> t;
    while(t--) {
        int n, k, d;
        cin >> n >> k >> d;
        int a[n];
        forn(i,0,n) cin >> a[i];
        set<int> st;
        int cnt[k];
        forn(i,0,k) cnt[i] = 0;
        int ans = inf;
        forn(i,0,n) {
            if(i<d) {
                cnt[a[i]-1]++;
                st.insert(a[i]);
            }
            else {
                ans = min(ans, (int)st.size());
                cnt[a[i-d]-1]--;
                cnt[a[i]-1]++;
                st.insert(a[i]);
                if(cnt[a[i-d]-1]==0) st.erase(a[i-d]);
                ans = min(ans, (int)st.size());
            }
        }
        ans = min(ans, (int)st.size());
        cout << ans << endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
vector<int>v;
vector<int>v1;
int arr[110],cnt[110];
set<int> s;
int main()
{

   int t;
   cin>>t;
   while(t--)
   {
       int n,i,k,d,flag=0,ans=1000;
       cin>>n>>k>>d;
       memset(arr,0,sizeof(arr));
       memset(cnt,0,sizeof(cnt));
        for(i=0;i<n;i++)
        {
            cin>>arr[i];
        }

        for(i=0;i<n;i++)
        {
            if(i<d)
            {
                s.insert(arr[i]);
                cnt[arr[i]]++;
            }
            else
            {
                s.insert(arr[i]);
                cnt[arr[i]]++;
                cnt[arr[i-d]]--;
                if(cnt[arr[i-d]]==0)
                    s.erase(arr[i-d]);
            }
            if(i>=d-1)
                ans=min(ans,(int)s.size());

//                cout<<i<<' '<<s.size()<<endl;
        }
       cout<<ans<<endl;
       s.clear();

   }

}

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <functional>
#include <cassert>
#include <cctype>
#include <string>
#include <sstream>
#include <bitset>
#include <list>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((ll)(x).size())
typedef vector<ll> VI;
typedef pair<ll, ll> PII;
const ll mod = 1000000007;
const int MAXN = 2e5 + 24;
const int MAXC = 1e6 + 24;
const int INF = 0x3f3f3f3f;
int num[MAXN], cnt[MAXC];
int main() {
#ifdef kirito
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // kirito
	int tCase;
	scanf("%d", &tCase);
	for (int _ = 0; _ < tCase; _++) {
		int n, k, len, ans = INF, cur = 0;
		scanf("%d %d %d", &n, &k, &len);
		memset(cnt, 0, sizeof(cnt));
		for (int i = 0; i < n; i++) {
			scanf("%d", &num[i]);
			cnt[num[i]]++;
			if (cnt[num[i]] == 1) {
				cur++;
			}
			if (i >= len - 1) {
				if (i - len >=0 && (--cnt[num[i - len]] == 0)) {
					cur--;
				}
				ans = min(ans, cur);
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

const int N = 100 + 5;

int a[N];

main(){

    int t;
    scanf("%d" , &t);

    while(t --){

            int n , k , d;
            scanf("%d %d %d" , &n , &k , &d);

            for(int i = 0 ; i < n ; i ++){
                    scanf("%d" , &a[i]);
            }

            int ans = k;
            for(int l = 0 ; l < n ; l ++){
                    for(int r = l ; r < n ; r ++){

                            set < int > shows;
                            for(int i = l ; i <= r ; i ++){
                                    shows.insert(a[i]);
                            }

                            if((r - l + 1 >= d)){
                                    ans = min(ans , (int)shows.size());
                            }
                    }
            }

            printf("%d\n" , ans);
    }
}

#include <iostream>
#include <vector>

using namespace std;

int main()
{
	int t;
	cin >> t;
	int n, k, d, *a, i, *begin, *end, *current, min;
	vector<int> buf;
	bool found;
	while (t--)
	{
		cin >> n >> k >> d;
		a = new int[n];
		for (i = 0; i < n; ++i)
			cin >> a[i];

		min = INT_MAX;
		// Посчитаем число подписок для каждого сегмента и выведем наименьшее
		for (begin=a, end=begin+d-1; end<=&a[n-1]; ++begin, ++end)
		{
			buf.clear();
			for (current = begin; current <= end; ++current)
			{
				found = false;
				for(int buffered : buf)
					if (buffered == *current)
					{
						found = true;
						break;
					}
				if(!found)
					buf.push_back(*current);
			}
			if (buf.size() < min)
				min = buf.size();
		}

		cout << min << endl;
		delete[] a;
	}
}

// Author-Priyanshu Kumar
// Birla Institute of Technology, Mesra

#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
//cpp_int
typedef long long int ll;
#define pb push_back
#define MOD 1000000007
#define vec vector<ll>

//sort(v.begin(), v.end());
//sort(v.begin(), v.end(),greater<int>());
//reverse(v.begin(), v.end());
//*max_element(v.begin(), v.end());
//*min_element(v.begin(), v.end());
//accumulate(v.begin(), v.end(), 0);
//count(v.begin(), v.end(), 20);
//find(first_iterator, last_iterator, x);
//lower_bound(first_iterator, last_iterator, x);
//upper_bound(first_iterator, last_iterator, x);
//distance(first_iterator,desired_position)
ll counta[1000001]={0};
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    ll t;
    cin>>t;
    for(ll i=0;i<t;i++)
    {

        ll n,k,d;
        cin>>n>>k>>d;
        ll a[n];set<ll> s;
        for(ll j=0;j<n;j++)
        {
            cin>>a[j];
            counta[a[j]]=0;
        }
        for(ll j=0;j<d;j++)
            {
            counta[a[j]]++;
            s.insert(a[j]);
            }
         ll mina=s.size();
        for(ll j=0;j<n-d;j++)
        {

            if(counta[a[j]]==1){
            s.erase(a[j]);
            counta[a[j]]--;
            }
            else
            {
                counta[a[j]]--;
            }
            s.insert(a[j+d]);
            counta[a[j+d]]++;
            ll e=s.size();
            mina=min(mina,e);

        }
        cout<<mina<<"\n";
        s.clear();
    }
    return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <iostream>
#define ll long long
using namespace std;
int a[200010];
int cnt[200010];
int main() {
	int t;
	scanf("%d", &t);
	while (t--) {
		int n, k, d;
		int tmp = 0;
		scanf("%d %d %d", &n, &k, &d);
		for (int i = 0; i < n; i++)
			scanf("%d", a + i);
		for (int i = 0; i < d; i++) {
			cnt[a[i]]++;
			if (cnt[a[i]] == 1)
				tmp++;
		}
		int res = tmp;
		for (int i = d; i < n; i++) {
			cnt[a[i]]++;
			if (cnt[a[i]] == 1)
				tmp++;
			cnt[a[i - d]]--;
			if (cnt[a[i - d]] == 0)
				tmp--;
			res = min(res, tmp);
		}
		printf("%d\n", res);
		for (int i = 0; i <= max(n, k); i++) {
			cnt[i] = 0;
			a[i] = 0;
		}
	}
}

//To debug :  g++ -g file.cpp -o code
//cout<<setprecision(p)<<fixed<<var
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{

	//FAST

	int t,n,k,d,ans,i,j,per;

	cin>>t;

	int a[200001];

	while(t--)
	{
		ans=0;
		cin>>n>>k>>d;

		map<int,int> mp;

	//	memset(c,0,sizeof(c));

		rep(i,0,n)
			cin>>a[i];

		for(i=0;i<d;++i)
		{
			++mp[a[i]];

			if(mp[a[i]]==1)
				++ans;
		}

		per = ans;

	//	cout<<per<<"\n";

		for(j=1;i<n;++j,++i)
		{
			--mp[a[j-1]];

			if(mp[a[j-1]]==0)
				--ans;

			++mp[a[i]];

			if(mp[a[i]]==1)
				++ans;

			if(ans<per)
				per=ans;

		//	cout<<per<<" "<<i<<"\n";

		}

		cout<<per<<"\n";
	}

	return 0;
}

#include <iostream>
#include <cstring>
#include <stdio.h>
#include <map>

using namespace std;

const int Max=1e6+7;
const int N=2*1e5+10;
int a[Max];
int vis[Max];

int main()
{
    int t; scanf("%d",&t);
    while(t--)
    {
        int n,k,d; scanf("%d%d%d",&n,&k,&d);

        memset(vis,0,sizeof vis);
        for(int i=1; i<=n; i++) scanf("%d",&a[i]);

        int ans=0;
        int tot=0;
        for(int i=1; i<=d; i++)
        {
           if(vis[a[i]]==0) tot++;
            vis[a[i]]++;
        }
        ans=tot;

        for(int i=d+1; i<=n; i++)
        {

            vis[a[i-d]]--;
            if(vis[a[i-d]]==0) tot--;
            if(vis[a[i]]==0) tot++;

            vis[a[i]]++;
            ans=min(ans,tot);
        }
        printf("%d\n",ans);
    }

    return 0;
}

    using namespace std;
    #include <bits/stdc++.h>
    #define ll long long
    #define pb push_back
    #define bb back()
    #define ff front()
    const ll inf=1e18;
    const ll mod=998244353;
    void boost(){
        ios_base::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int main(){
        boost();
        int t;
        cin>>t;
        while (t--) {
            int n,k,d,i,j;
            int f[101],a[101];
            cin>>n>>k>>d;
            int ans=k;
            for(i=1;i<=n;i++) {
                cin>>a[i];
            }
            for(i=1;i<=n-d+1;i++) {
                int q=0;
                for(j=1;j<=k;j++) f[j]=0;
                for(j=i;j<=i+d-1;j++) {
                    f[a[j]]++;
                }
                for(j=1;j<=k;j++) q+=(f[j]>0);
                ans=min(ans,q);
            }
            cout<<ans<<endl;
        }
        return 0;
    }

//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;
//ok
//int input........
template <typename T> inline void readline(T &n) {n = 0; int f = 1; register int ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readline(T &n, TT &m) { readline(n); readline(m); }
template <typename T, typename TT, typename TTT> inline void readline(T &n, TT &m, TTT &l) { readline(n, m); readline(l);}
// long long input........
template <typename T> inline void readlinel(T &n) {n = 0; long long f = 1; register long long ch = getchar();
 for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;for (; isdigit(ch);
ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';n = n * f;}
template <typename T, typename TT> inline void readlinel(T &n, TT &m) { readlinel(n); readlinel(m); }
template <typename T, typename TT, typename TTT> inline void readlinel(T &n, TT &m, TTT &l) { readlinel(n, m); readlinel(l);}
//debug..........
#define error(args...) {vector<string>_v=split(#args,',');err(_v.begin(),args);cout<<endl;}
vector<string> split(const string &s, char c) {vector<string>v; stringstream ss(s); string x;
while (getline(ss, x, c))v.emplace_back(x); return move(v);} void err(vector<string>::iterator it) {}
template<typename T, typename... Args>void err(vector<string>::iterator it, T a, Args...args) {
cout << it->substr((*it)[0] == ' ', it->length()) << " = " << a << " "; err(++it, args...);}
//............ignore it..................//
int dx[8]= {1,0,-1,0,-1,-1,1,1};int dy[8]= {0,1,0,-1,-1,1,-1,1}; int tc = 1;
#define pb  push_back
#define mp make_pair
#define Pi atan(1)*4
#define ll  long long int
#define happy cin.tie(0);
#define point(x) setprecision(x)
#define coding ios::sync_with_stdio(false);
#define Test printf("Case %d: ",tc++);
#define Unique(c) (c).resize(unique(all(c))-(c).begin())
#define vout(v) for (auto z: v) cout << z << " "; cout << endl;
void print(int n){printf("%d ", n);}
void print(int n,int m){printf("%d ",n);printf("%d ",m);}
void print(int n,int m,int k){printf("%d ",n);printf("%d ",m);printf("%d ",k);}
void print(ll n){printf("%I64d ", n);}
void print(ll n,ll m){printf("%I64d ",n);printf("%I64d ",m);}
void print(ll n,ll m,ll k){printf("%I64d ",n);printf("%I64d ",m);printf("%I64d ",k);}
#define   pr 	pair<int, int>
#define   vpr 	vector<pr>
#define   vi   	std::vector<int>
#define   vll  	std::vector<ll>
#define   all(n) n.begin(),n.end()
const int M           	= 1e9 + 7;
const int Inf           = (int)2e9 + 5;
const ll  Lnf           = (ll)2e18 + 5;
const int N             = 4e5 + 5;
const int N1            = 1e5 + 5;

ll a[N];

int MinimumDifferentNumber(long long n,long long m,long long a[]){

	std::map<ll, ll>vis;
	long long cnt  = 0;
	for(long long i=0;i<m;i++){
		if(vis[a[i]]==0){
			cnt++;
		}vis[a[i]]++;
	}
	long long mn = cnt;
	for(long long i=m;i<n;i++){
		if(vis[a[i]]!=0){
			if(a[i]!=a[i-m]&&vis[a[i-m]]==1) {
				cnt--;
			}
				vis[a[i-m]]--;
				vis[a[i]]++;
		}else{
			if(vis[a[i-m]]>1){
			 	cnt++;
			}
			vis[a[i-m]]--;
			vis[a[i]]++;
		}
		mn = min(mn,cnt);
	}
	for(long long i=0;i<n;i++){
		vis[a[i]] = 0;
	}

	//cout<<mn<<endl;
	return mn;
}

int solve()
{
	//happy coding

	ll n,k,m;
	cin>>n>>k>>m;
	for(ll i=0;i<n;i++){
		cin>>a[i];
	}
	cout<<MinimumDifferentNumber(n,m,a)<<endl;

	return 0;
	//error();
}
int main(){
	int test = 1;
	readline(test);//(void)getchar();
	while (test--)solve();return 0;
}

#include <iostream>
#include <cstdio>

#include <functional>
#include <utility>
#include <cmath>
#include <algorithm>
#include <cassert>

#include <vector>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <unordered_map>

#include <string>
#include <iterator>
#include <iomanip>
#include <fstream>

using namespace std;

#define uint unsigned int
#define prll pair<ll,ll>
#define prdd pair<double,double>
#define m_p make_pair
#define ticonst (ll)1337228
#define INF (ll)1e18
#define ll long long

const ll q = 239053;
const ll mod = 1e9 + 7;
const ll mod2 = 1e9 + 13;
const ll MAXN = 1e6 + 100;
const ll MAXM = 150;
const ll L = 26;

void $main()
{
	ll t; cin >> t;
	while (t--)
	{
		ll n, k, d; cin >> n >> k >> d;

		map<ll,ll> ct;

		vector<ll> v(n);
		for (ll i = 0; i < n; ++i)
			cin >> v[i];

		set<ll> unic;

		ll l = 0, r = d - 1;

		for (ll i = l; i <= r; ++i)
		{
			++ct[v[i]];
			unic.insert(v[i]);
		}

		ll ans = (ll)unic.size();
		while (r < n)
		{
			--ct[v[l]];

			if (!ct[v[l]])
				unic.erase(v[l]);

			++l; ++r;

			if (r < n)
			{
				++ct[v[r]];
				unic.insert(v[r]);
				ans = min(ans, (ll)unic.size());
			}
		}

		cout << ans << '\n';
	}
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
#else
	//freopen("wizard.in", "r", stdin);
	//freopen("wizard.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);

	$main();

	return 0;
}

//257593BA

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;

void test() {
	ll n, k, d; cin >> n >> k >> d;
	vl arr(n);
	for(ll i = 0; i < n; i++) cin >> arr[i];

	ll output = 4000000000LL;
	map<ll, ll> counts;

	for(ll i = 0; i < d; i++) {
		counts[arr[i]]++;
	}

	output = counts.size();
	for(ll i = d; i < n; i++) {
		counts[arr[i - d]]--;
		if(counts[arr[i - d]] == 0) {
			counts.erase(arr[i - d]);
		}

		counts[arr[i]]++;

		output = min(output, (ll) counts.size());
	}

	cout << output << endl;
}

int main() {
	ll t; cin >> t; while(t--) test();
}

#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
//#include <boost/lexical_cast.hpp>
using namespace std;
  #define ll  long long
    #define rep(i,n) for(ll i=0;i<n;i++)
    #define pb push_back
    #define in insert
    #define pll pair<ll,ll>
    #define mll map<ll,ll>
    #define si set<ll>
    #define sc set<char>
    #define msi multiset<ll>
    #define msc multiset<char>

   // #define bs  binary_search
    #define rep1(x,n) for(ll x=n-1;x>=0;x--)
    #define for1(i,a,n) for(ll i=a;i<n;i++)
    #define for2(i,a,n) for(ll i=n-1;i>=a;i--)
    #define F1 first
    #define S2 second
    #define vi vector<ll>
    #define vii vector<vector<ll>>
    #define vpi vector<pll>
    #define SORT(x) sort(x.begin(),x.end())
    #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
    #define All(x) (x).begin(),(x).end()
    #define rAll(x) (x).rbegin(),(x).rend()
    #define db  double
    #define S size()
    #define EN end()
    #define BE begin()
    #define LEN length()
    #define itr(s) for(auto x:s)
    #define srt(x)  sort(x,x+n)

    const ll MAX=1e18+1;

    const double pi=3.1415926535897932384626433832;
    const ll M=1e9 +7;
    ll bis(ll a[],ll l,ll r,ll x){
     while(l<=r){
      ll m=l +(r-l)/2;
      if(a[m]==x)
      return m;
      if(a[m]<x)l=m+1;
      else r=m-1;
     }
     return -1;
    }

    ll gcd(ll x,ll y){
        if(x==0)return y;
        else return gcd(y%x,x);
    }
    ll lcm(ll x,ll y){
        return (x*y)/gcd(x,y);
    }

bool isPrime(ll n)
{
    if (n <= 1)
        return false;
    if (n <= 3)
        return true;
    if (n % 2 == 0 || n % 3 == 0)
        return false;

    for (ll i = 5; i * i <= n; i = i + 6){
        if (n % i == 0 || n % (i + 2) == 0){
            return false;
        }
    }
    return true;
}
bool pdrome(string s){
    ll n = s.length();
    for(ll i=0;i<n/2;i++){
        if(s[i]!=s[n-i-1]){
            return false;
        }
    }
    return true;
}
string need(string s){
    string a=s;
    reverse(a.begin(),a.end());
    a=s+'?'+a;
    ll n=a.size();
    ll pref[n];
    memset(pref,0,sizeof(pref));
    //ll len=0;
    for1(i,1,n+1){
        ll len=pref[i-1];
         while(len>0&&a[len]!=a[i])len=pref[len-1];
         if(a[i]==a[len])len++;
         pref[i]=len;
    }
    //cout<<pref[n-1];
    return a.substr(0,pref[n-1]);
}

ll mindig(ll x){
    ll ans = 9;
    ll t = x;
    while(x){
        ans = min(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll maxdig(ll x){
    ll ans = 0;
    ll t = x;
    while(x){
        ans = max(ans,x%10);
        x/=10;
    }
    x = t;
    return ans;
}
ll modpow(ll x,ll n,ll M){
    if(n==0)return 1%M;
    ll u=modpow(x,n/2,M);
    u=(u*u)%M;
    if(n%2==1)u=(u*x)%M;
    return u;

}
ll sumdigits(ll a) {
    ll result = 0;
    while (a > 0) {
        result += a % 10;
        a /= 10;
    }
    return result;
}
ll digits(long long n)
{
    return floor(log10(n) + 1);
}
const ll Node=1e5+7;
vi adj[Node];
bool vis[Node]={false};
void addedge(ll u,ll v){
    adj[u].pb(v);
    adj[v].pb(u);
}
void bfs(ll u){
    vis[u]=true;
    list<ll>q;
    q.pb(u);
    while(!q.empty()){
        //cout<<q.front()<<" ";
        q.pop_front();
        for(auto x:adj[u]){
            if(!vis[x]){
                vis[x]=true;
                q.pb(x);
            }
        }
    }
}
void dfs(ll u){
    vis[u]=true;
    cout<<u<<" ";

    itr(adj[u]){
        if(!vis[x]){

        //cnt++;
        dfs(x);
        }
    }

}
ll con1(string s){
    long long res=0;
    stringstream geek(s);
    geek>>res;
    return res;

}
string con2(ll num){

    string stri=to_string(num);
    return stri;
}
ll countbits(ll k){
    ll cnt=log2(k);
    return cnt;

}

//ll ans;
void solve(){
   ll n,k,d;
   cin>>n>>k>>d;
   ll a[n];rep(i,n)cin>>a[i];
   ll ans=200;//map<ll,ll>mp;
   for1(i,0,n-d+1){
      set<ll>s;
    for1(j,i,d+i){
        s.insert(a[j]);
    }
    if(s.size()<ans){
    ans=s.size();}

   }
   cout<<ans<<endl;

    return;

    }

int main(){

        #ifndef ONLINE_JUDGE
               freopen("input.txt","r",stdin);
               freopen("output.txt","w",stdout);
               #endif
               ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
      ll t=1;
    cin>>t;

      while(t--){

           solve();
      }

        return 0;
}

#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
int t;
	cin>>t;
	while(t--)
	{
		int n,k,d,i,j,arr[200000];
		cin>>n>>k>>d;
		for(i=0;i<n;i++)
		{
			cin>>arr[i];
		}
		map<int ,int >mp;
		for(i=0;i<d;i++)
		{
			mp[arr[i]]++;
		}
		int mini=mp.size();
		for(i=d;i<n;i++)
		{
			mp[arr[i-d]]--;
			if(mp[arr[i-d]]==0)
			{
				mp.erase(arr[i-d]);
			}
			mp[arr[i]]++;
			mini=min((int)mp.size(),mini);
		}
		cout<<mini<<endl;
	}
	return 0;
}

/*
 * socode.online
 *
 * Author: t14
 * E-mail: 2696123231@qq.com
 * Time  : 2020-01-20 19:05:31
 */
#include <bits/stdc++.h>

using namespace std;
int a[200010], cnt[1000010];

int main() {
	int T; scanf("%d", &T);
	while (T--) {
		memset(cnt, 0, sizeof cnt);
		int n, k, d, sum = 0; scanf("%d%d%d", &n, &k, &d);
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= d; i++) {
			if (cnt[a[i]] == 0) sum++;
			cnt[a[i]]++;
		}
		int ans = sum;
		for (int i = d+1; i <= n; i++) {
			if (cnt[a[i]] == 0) sum++;
			cnt[a[i]]++;
			cnt[a[i-d]]--;
			if (cnt[a[i-d]] == 0) sum--;
			ans = min(ans, sum);
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define TFiOS ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define int ll
#define pb push_back
#define endl "\n"
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
const int MOD = 1e9+7;

int32_t main()
{
    TFiOS

    int t,n,k,d;
    cin >> t;
    while(t--)
    {
        cin >> n >> k >> d;
        int a[n];
        for(int i=0;i<n;i++)
            cin >> a[i];
        if(d==1)
        {
            cout << 1 << endl;
            continue;
        }
        int ans = n, c=0, j=0;
        unordered_map<int,int> m;
        for(int i=0;i<d;++i)
        {
            m[a[i]]++;
            if(m[a[i]]==1)
                c++;
        }
        ans = min(ans,c);
        for(int i=d;i<n;i++)
        {
            m[a[j]]--;
            if(m[a[j]]==0)
                c--;
            j++;
            m[a[i]]++;
            if(m[a[i]]==1)
                c++;
            ans=min(ans,c);
        }
        cout << ans << endl;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;
const int maxn = 200005;

int N, a[maxn], k, d, T;
int num[1000005];

int main()
{
    cin >> T;
    while (T--)
    {
        scanf("%d%d%d", &N, &k, &d);
        int ans = d;
        int now = 0;
        fill(num, num + k + 1, 0);
        for (int i = 1; i <= N; ++i)
        {
            scanf("%d", &a[i]);
            if (++num[a[i]] == 1)
                ++now;
            if (i - d >= 1)
            {
                if (!--num[a[i - d]])
                    --now;
            }
            if (i >= d)
                ans = min(ans, now);
        }
        cout << ans << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define F first
#define S second
ll INF=1e9;

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;
        vector<int> a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        int ans=INF;
        for(int i=0;i<=n-d;i++)
        {
            vector<bool> bg(k+1);
            int sum=0;
            for(int j=i;j<i+d;j++)
            {
                if(bg[a[j]]==false)
                {
                    sum++;
                    bg[a[j]]=true;
                }
            }
            ans=min(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	ios::sync_with_stdio(false);
	int t, n, k, d;
	cin >> t;
	while (t--) {
		int tv[105], used[105] = {0};
		cin >> n >> k >> d;
		int minx = d, firstnum, num = 0, que[105] = {0}, head = 1, tail = d;
		for (int i = 1; i <= n; i++) {
			cin >> tv[i];
			if (i <= d) {
				que[i] = tv[i];
				if (!used[tv[i]]) {
					num++;
					used[tv[i]] = 1;
				}
			}
			else
			{
				if (i == d + 1) {
					minx = min(num, minx);
				}
				int t = head;
				head++, tail++;
				int notchange = 0;
				for (int j = head; j < tail; j++) {
					if (que[t] == que[j]) {
						notchange = 1;
						break;
					}
				}
				if (!notchange) {
					used[que[head-1]] = 0;
					num--;
				}
				que[tail] = tv[i];
				if (!used[tv[i]]) {
					used[tv[i]] = 1;
					num++;
				}
				minx = min(num, minx);
			}
		}
		minx = min(num, minx);
		cout << minx << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int cnt[2000009],ara[2000009];

int main(){

	// freopen("in.txt","r",stdin);

	int test;
	cin>>test;

	for(int ts=0;ts<test;ts++){

		int n,k,d;
		cin>>n>>k>>d;

		for(int i=0;i<n;i++){
			cin>>ara[i];
		}

		int td=d;

		int tot=0,mn=1000000009,flag=0;
		for(int i=0,j=0;i<n && j<n;){

			while(1){

				if(td==1)
					break;
				else
					td--;

				if(cnt[ara[j]]==0)
					tot++;

				cnt[ara[j]]++;
				j++;

			}

			if(flag==0){
				if(cnt[ara[j]]==0)
					tot++;

				cnt[ara[j]]++;

				mn=min(mn,tot);
				flag=1;
			}

			// printf("%d %d\n",i,j );

			// 	for(int i=0;i<n;i++)
			// 		printf("%d ->%d\n",ara[i], cnt[ara[i]] );

			// puts("");

			j++;
			if(j==n)
				break;

			if(cnt[ara[j]]==0)
				tot++;
			cnt[ara[j]]++;

			cnt[ara[i]]--;

			if(cnt[ara[i]]==0)
				tot--;

			i++;

			mn=min(mn,tot);

		}

		mn=min(mn,tot);

		// if(d==1)
		// 	cout<<1<<endl;
		// else
		// printf("Case %d:\n", ts+1);

		// printf("%d %d %d\n",n,k,d );

		// for(int i=0;i<n;i++)
		// 	printf("%d ",ara[i]);
		// puts("");
		cout<<mn<<endl;
			// cout<<mn<<endl;

		for(int i=0;i<n;i++){
			cnt[ara[i]]=0;
			ara[i]=0;
		}

	}

}

#include <iostream>

const int DIM = 1000005;
int f[DIM];

int main() {

  int t;
  std::cin >> t;
  while (t--) {
    int n, k, d;
    std::cin >> n >> k >> d;
    int a[5 + n];
    for (int i = 1; i <= n; i++) {
      std::cin >> a[i];
      f[a[i]] = 0;
    }
    int size = 0, answer;
    for (int i = 1; i <= d; i++) {
      f[a[i]]++;
      if (f[a[i]] == 1)
        size++;
    }
    answer = size;
    for (int i = d + 1; i <= n; i++) {
      f[a[i - d]]--;
      if (f[a[i - d]] == 0)
        size--;
      f[a[i]]++;
      if (f[a[i]] == 1)
        size++;
      answer = std::min(answer, size);
    }
    std::cout << answer << '\n';
  }

  return 0;
}

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int; //// this is for very large input
using namespace std;
#define fasto ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define afor(i,a,b) for(ll i=a;i<b;i++)
#define bfor(i,a,b) for(ll i=a-1;i>=b;i--)
#define tc() ll t; cin>>t; while(t--)
#define pb push_back
#define all(c)  c.begin(),c.end()
#define fi first
#define se second
#define M 1000000007
#define INF 1000000000
#define mset(x,v) memset(x, v, sizeof(x))
#define vll vector<ll>
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define N 100050

const ll MAXK=1e6+10,MAXN=2e5+10;
ll dp[MAXK],v[MAXN];

int main(){
	fasto;
	tc(){
	    ll n,k,d,x;
	    cin>>n>>k>>d;
	    afor(i,0,n){
	        cin>>v[i];
	    }
	    ll cnt=0,mini=INT_MAX;
	    afor(i,0,d){
	        if(dp[v[i]]==0){
	            cnt++;
	        }
	        dp[v[i]]++;
	    }
	    mini=cnt;
	   // cout<<cnt<<" ";
	    afor(i,1,n-d+1){
	        dp[v[i-1]]--;
	        if(dp[v[i-1]]==0){
	            cnt--;
	        }
	        if(dp[v[i+d-1]]==0){
	            cnt++;
	        }
	        dp[v[i+d-1]]++;
	       // cout<<cnt<<" ";
	        mini=min(cnt,mini);
	    }
	    cout<<mini<<"\n";
	    afor(i,0,n){
	        dp[v[i]]=0;
	    }
	}
}

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <cmath>
#include <algorithm>
#include <set>

#define ll long long

using namespace std;

int main() {
    int t;
    cin>>t;
    for(int i = 0; i < t; ++i){
        ll n,k,d;
        cin>>n>>k>>d;
        vector<ll> arr(n);
        map<ll, ll> map1;
        for(int i = 0; i< n;++i){
            cin>>arr[i];
        }
        for(int i = 0; i<d; ++i){
            map1[arr[i]]++;
        }
        ll rez = map1.size();

        for(int i = d; i < n; ++i) {
            --map1[arr[i-d]];
            ++map1[arr[i]];
            if(map1[arr[i-d]] == 0){
                map1.erase(arr[i-d]);
            }
            if(rez>map1.size()){
                rez = map1.size();
            }
        }
        cout<< rez <<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main() {
	int q,r;
	cin >> q;
	for(r=0;r<q;r++){
		int n,k,d,i,a[200005],m=0,memo;
		int b[1000005];
		memset(b, 0, sizeof b);
		cin >> n >> k >> d;
		for(i=0;i<n;i++){
			cin >> a[i];
		}
		for(i=0;i<d;i++){
			if(b[a[i]]==0) m++;
			b[a[i]]++;
		}
		memo=m;
		for(i=d;i<n;i++){
			if(b[a[i]]==0) memo++;
			b[a[i]]++;
			b[a[i-d]]--;
			if(b[a[i-d]]==0) memo--;
			m=min(memo,m);
		}
		cout << m << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#include <string>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <iostream>

#define vpii vector< pair<int,int> >
#define vi vector<int>

#define for0(i,a) for(int i=0;i<a;i++)
#define pii              pair <int,int>
#define pll              pair <long long,long long>
#define sc               scanf
#define pf               printf
#define Pi               2*acos(0.0)
#define ms(a,b)          memset(a, b, sizeof(a))
#define pb(a)            push_back(a)
#define MP               make_pair
#define db               double
#define ll               long long
#define ull              unsigned long long
#define f                first
#define s                second
#define sqr(x)           (x)*(x)
#define VI               vector <int>
#define DBG              pf("Hi\n")
#define MOD              1000000007
#define SZ(a)            (int)a.size()
#define sf(a)            scanf("%d",&a)
#define sfl(a)           scanf("%lld",&a)
#define sff(a,b)         scanf("%d %d",&a,&b)
#define sffl(a,b)        scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)      scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)     scanf("%lld %lld %lld",&a,&b,&c)
#define loop(i,n)        for(int i=0;i<n;i++)
#define loop1(i,n)       for(int i=1;i<=n;i++)
#define REP(i,a,b)       for(int i=a;i<b;i++)
#define RREP(i,a,b)      for(int i=a;i>=b;i--)
#define intlim           2147483648
#define ull              unsigned long long
#define gcd(a, b)        __gcd(a, b)
#define lcm(a, b)        ((a)*((b)/gcd(a,b)))
#define mk(x1,y1) make_pair(x1, y1)
#define maxl 10000
#define psz 20
#define Fin      freopen("input.txt","r",stdin)
#define Fout     freopen("output.txt","w",stdout)

/*----------------------Graph Moves----------------*/
const int fx[]={+1,-1,+0,+0};
const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

/*-----------------------Bitmask------------------*/
//int Set(int N,int pos){return N=N | (1<<pos);}
//int reset(int N,int pos){return N= N & ~(1<<pos);}
//bool check(int N,int pos){return (bool)(N & (1<<pos));}
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
//ios_base::sync_with_stdio(false);
 //cin.tie(NULL);

using namespace std;

int main()
{
    int t;
    cin >> t;

    while(t--){
        int n, k, d;

        cin >> n >> k >> d;

        //int mp[k + 10];

        int a[n + 5];

        for(int i = 0; i < n; i++){

            cin >> a[i];
        }

        map<int, int>mp;

        int ans = 1e9;

        int cn = 0, j = 0, tot = 0;

        for(int i = 0; i < n; i++){

            tot++;

            if(tot <= d){

                if(mp[a[i]] == 0){
                    mp[a[i]]++;
                    cn++;
                }
                else mp[a[i]]++;

                if(tot == d){
                     ans = min(ans, cn);
                }
            }
            else{

                if(mp[a[i]] == 0){
                    mp[a[i]]++;
                    cn++;
                }
                else mp[a[i]]++;

                if(mp[a[j]] > 0) {
                    mp[a[j]]--;

                    if(mp[a[j]] == 0) cn--;
                }
                ans = min(ans, cn);
               //  cout<<"T  "<<tot<<"  "<<cn<<"  "<<j<<endl;

                j++;

            }

        }
        ans = min(ans, cn);

        cout<<ans<<endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
	 ll ans,t,n,i,x,a,b,j,k;
	cin>>t;
	while(t--){
	    cin>>n>>x>>k;
	    ll arr[n+2]={0};
	    for(i=0;i<n;i++)
	     cin>>arr[i];
	    map<ll,ll> m;

	    for(i=0;i<k;i++)
	     m[arr[i]]++;

	    ans=m.size();
	    for(i=k;i<n;i++){

	        m[arr[i]]++;
	        if(m[arr[i-k]]==1){
	            m.erase(arr[i-k]);
	        }else
	        m[arr[i-k]]--;
	        ll tmp=m.size();
	        ans=(ans<tmp)?ans:tmp;
	    }
	    m.clear();
	    cout<<ans<<"\n";
	}

	return 0;
}

//TV SUBSCRIPTIONS(EASY VERSION)

#include<bits/stdc++.h>
#define ll long long int

using namespace std;

void shows(int n, vector<int> v, int k, int d)
{
	int min, count=0, i, j;
	map<int,int> m1;

		for(i=0; i<=n-d; i++)
		{
			map<int,int> m2;
			count=0;
			for(j=i; j<i+d; j++)
			{
				if(m2.find(v[j])==m2.end())
				{
					m2[v[j]]==1;
					count++;
				} //if
			} //inner for
			m1[i]=count;
			m2.clear();
		} //outer for

		min= m1[0];
		for(i=1; i<=n-d; i++)
		{
			if(m1[i]<min)
			  min=m1[i];
		}

	cout<<min<<"\n";
	m1.clear();
}

int main()
{
	int t, i, a;
	int n, k, d;

	cin>>t;

	while(t--)
	{
		vector<int> v;
		cin>>n>>k>>d;
		for(i=0; i<n; i++)
		{
			cin>>a;
			v.push_back(a);
		}
		shows(n, v, k, d);
		v.clear();
	}

	return 0;
}

#include<iostream>
#include<cstdio>
#include<map>
using namespace std;
const int N=2e5+7;
map<int,int>mp;
int arr[N],T,n,m,k;
int main(){
    scanf("%d",&T);
    while(T--){
    	mp.clear();
	    scanf("%d%d%d",&n,&m,&k);
	    for(int i=1;i<=n;i++) scanf("%d",&arr[i]);
	    int ans=0;
	    for(int i=1;i<=k;i++){
	        if(mp[arr[i]]==0) ans++;
	        mp[arr[i]]++;
	    }
	    int sum=ans;
	    for(int j=k+1,i=1;j<=n;j++,i++){
	        if(mp[arr[i]]==1) ans--;mp[arr[i]]--;
	        if(mp[arr[j]]==0) ans++;mp[arr[j]]++;
	        sum=min(ans,sum);
	    }
	    printf("%d\n",sum);
	}
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
   int q;
   cin >> q;
   while(q--)
   {
       int n,k,d;
       int mini;
       cin >> n >> k >> d;
       int A[n];
       for(int i=0;i <n;i++)
          cin >> A[i];
       mini = 200;
       for(int i =0;i<=n-d;i++)
       {
           int B[102] = {0};
           int j=i;
           int count = 0;
           while(j < i+d)
           {
               int n1;
               n1 = A[j];
               if(B[n1]==0)
                 {
                     B[n1]++;
                     count++;
                     j++;
                 }
                else
                {
                    j++;
                }
           }
           if(count < mini) {
              mini = count;
           }
       }
       cout << mini << endl;

   }
}

#include <bits/stdc++.h>
using namespace std;
set <int> st;
int b[1000005];
int main()
{
	ios::sync_with_stdio(0);
		int q;
	   cin>>q;
	   for(int i=0; i<q; i++){
	   	int n,k,d;
	   	cin>>n>>k>>d;

	   	int a[n];
	   	for(int j=0; j<n; j++){
	   		cin>>a[j];
		}
		int ans=0,minn=INT_MAX;

		for(int j=0; j<d; j++){
			st.insert(a[j]);
			b[a[j]]++;
		}

		minn=st.size();

		for(int l=0; l<n-d; l++){
			//cout<<st.size()<<" 1   l="<<l+1<<endl;
			b[a[l]]--;

			if(b[a[l]] == 0){
				st.erase(a[l]);
			}
			//cout<<st.size()<<" 2"<<endl;
			st.insert(a[l+d]);
			b[a[l+d]]++;
			//cout<<st.size()<<" a[l+d]="<<a[l+d]<<endl;
			ans=st.size();
			minn=min(minn,ans);
		}
		cout<<minn<<endl;
		st.erase(st.begin(),st.end());
		for(int j=0; j<100005; j++){
		    b[j]=0;
		}
		//cout<<st.size()<<" 4"<<endl<<endl;
	}
	return 0;

}

#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
using namespace std;

using l = long int;
using ll = long long int;
#define imax INT_MAX
#define lmax LLONG_MAX
#define pb push_back
#define ld long double
#define pii pair<l,l>
#define pll pair<ll,ll>
#define v vector
#define vl vector<l>
#define vll vector<ll>
#define vvl vector<vector<l>>
#define vvll vector<vector<ll>>
#define vv(a) vector<vector<a>>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define mni(a,i,j) *min_element((a).begin()+i,(a).begin()+j)
#define mxi(a,i,j) *max_element((a).begin()+i,(a).begin()+j)
#define f first
#define se second
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
#define rep(i, begin, end) \
        for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define tc l t=0;cin>>t;while(t--)

// ONLINE JUDGE START
#ifndef ONLINE_JUDGE
    // FILE
    #define file ifstream cin; cin.open("input.txt");  ofstream cout; cout.open("output.txt");
    // DEBUG
    #define debug(x) cout<<"LINE NUMBER:     "<<__LINE__<<"\t :--> \t"<<#x<<"   =   "<<x<<endl;
#else
    #define debug(x)
#endif

// SYSTEM
#define DeBuG(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#define time__(d) for(long blockTime=NULL;(blockTime==NULL?(blockTime=clock())!=NULL:false); \
            DeBuG("%s:%.4f s\n",d,(double)(clock()-blockTime)/CLOCKS_PER_SEC))
// OVERLOADING
istream& operator >> (istream& cin,vll &a){
    for(auto &i:a)cin>>i;
    return cin;
}
ostream& operator << (ostream& cout,pll &a){
    cout<<a.f<<" "<<a.se<<"\t";
    return cout;
}
ostream& operator << (ostream& cout,vl &a){
    for(auto &i:a)cout<<i<<" ";
    return cout;
}
ostream& operator << (ostream& cout,vll &a){
    for(auto &i:a)cout<<i<<" ";
    return cout;
}
ostream& operator << (ostream& cout,v<pll> &a){
    for(auto &i:a)cout<<i<<"\t";
    return cout;
}
ostream& operator << (ostream& cout,vvl &a){
    for(auto &i:a){cout<<i<<endl;}
    return cout;
}
ostream& operator << (ostream& cout,vvll &a){
    for(auto &i:a){cout<<i<<endl;}
    return cout;
}
ostream& operator << (ostream& cout,unordered_map<ll,bool> &a){
    for(auto &i:a){cout<<i.f<<" "<<i.se<<"\t";}
    return cout;
}
ostream& operator << (ostream& cout,map<ll,ll> &a){
    for(auto &i:a){cout<<i.f<<" "<<i.se<<"\t";}
    return cout;
}
ostream& operator << (ostream& cout,set<ll> &a){
    for(auto i:a)cout<<i<<" ";
    return cout;
}

// GLOBAL VARIABLE AND FUNTIONS
const ll inf = 1e9+7;

int main()
{
#ifndef ONLINE_JUDGE
    file;
#endif

    tc{
        ll n,k,d;cin>>n>>k>>d;
        vll arr(n);cin>>arr;
        ll mn;
        map<ll,l> mp;
        for(l i=0;i<d;i++){
            mp[arr[i]]++;
        }
        mn=mp.size();
        ll curr_mn=mn;
        for(ll i=0;i<n-d;i++){
            if(arr[i]!=arr[i+d]){
                if(mp[arr[i]]==1&&mp[arr[i+d]])curr_mn--;
                if(mp[arr[i]]>1&&mp[arr[i+d]]==0)curr_mn++;
                mp[arr[i]]--;
                mp[arr[i+d]]++;
                mn=min(mn,curr_mn);
            }
        }
        cout<<mn<<endl;
    }

#ifndef ONLINE_JUDGE
    cerr << "Time elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms.\n";
#endif
    return 0;
}

#include <iostream>
#include <vector>
#include <queue>

int main() {
    int nt;
    std::cin >> nt;
    for (int ii = 0, n, k, d; ii < nt; ++ii) {
        std::cin >> n >> k >> d;
        std::vector<int> a(n);
        for (int i = 0; i < n; ++i) {
            std::cin >> a[i];
            --a[i];
        }
        std::vector<int> used(k);

        int i = 0, j = 1;
        used[a[i]] = 1;
        int ans = INT_MAX, cur = 1;
        if (d == 1)
            ans = cur;
        while (j < n) {
            while (j < n && j - i < d) {
                if (used[a[j]] == 0) {
                    ++cur;
                }
                ++used[a[j]];
                ++j;
            }
            if (j - i == d) {
                ans = std::min(cur, ans);
            }
            if (!--used[a[i]]) {
                --cur;
            }
            ++i;
        }
        std::cout << ans << '\n';
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

vector<int> shows;

int main() {
	int testCases;
  cin >> testCases;

  for (int j = 0; testCases > j; j++) {
    int n, k, d;
    cin >> n >> k >> d;

    shows.clear();

    int use[1000000] = {0};

    for (int i = 0; n > i; i++) {
      int temp;
      cin >> temp;

      shows.push_back(temp);
    }

    int purcase = 0;

    // Elso d nap

    for (int i = 0; d > i; i++) {
      if (use[shows[i]-1] == 0) {
        purcase++;
      }
      use[shows[i]-1]++;
    }

    int minPurchase = purcase;

    for (int i = d; n > i; i++) {
      if (use[shows[i-d]-1] == 1) {
        purcase--;
      }
      use[shows[i-d]-1]--;

      if (use[shows[i]-1] == 0) {
        purcase++;
      }
      use[shows[i]-1]++;

      minPurchase = min(minPurchase, purcase);
    }

    cout << minPurchase << endl;
  }

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
int wq[200007],k[1000003];
int main()
{
    int g,h,t,q,w,e,re,nt;
    scanf("%d",&t);
    while(t--){
        scanf("%d %d %d",&q,&w,&e);
        for(g=0;g<q;g++)scanf("%d",&wq[g]);
        h=nt=0;
        while(h<e){
            if(!k[wq[h]])nt++;
            k[wq[h]]++,h++;
        }
        re=nt;
        for(g=0,h=e;h<q;g++,h++){
            k[wq[g]]--;
            if(!k[wq[g]])nt--;
            if(!k[wq[h]])nt++;
            k[wq[h]]++;
            re=min(re,nt);
        }
        printf("%d\n",re);
        memset(k,0,sizeof k);
    }
    return 0;
}

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <bitset>
#include <fstream>
#include <cstdlib>
#include <functional>
#include <climits>
#include <queue>
#include <ctime>
#include <cassert>
#include <unordered_map>

#define mp make_pair
#define pb emplace_back

using namespace std;

void sol() {
	unordered_map<int, int> ff;
	vector<int> a;
	int n, k, d, cnt = 0, min_cnt = INT_MAX;
	cin >> n >> k >> d;
	for (int i = 0; i < k; ++i) {
		ff[i + 1] = 0;
	}
	for (int i = 0; i < n; ++i) {
		int f;
		cin >> f;
		a.pb(f);
		ff[f] += 1;
		if (ff[f] == 1) {
			++cnt;
		}
		if (i >= (d - 1)) {
			min_cnt = min(cnt, min_cnt);
			ff[a[i - d + 1]] -= 1;
			if (ff[a[i - d + 1]] == 0) {
				cnt -= 1;
			}
		}
	}
	cout << min_cnt << endl;
}

int main() {
	int t;
	cin >> t;
	for (int i = 0; i < t; ++i) {
		sol();
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
# define ll long long int
int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ll t;
	cin >> t;
	while (t--) {
		ll n, k, d;
		cin >> n >> k >> d;

		vector<int> vec;
		for (int i = 0; i < n; i++) {
			ll num;
			cin>>num;
			vec.push_back(num);
		}

		ll miin = 1e9;
		map<ll, ll> mp;

		ll sz = 0;
		for (int i = 0; i < d;  i++) {

			mp[vec[i]]++;
			if (mp[vec[i]] == 1) {
				sz++;
			}

		}
		// cout<<sz<<"\n";

		miin = min(miin, sz);
		// cout<<miin<<"\n";

		for (int i = d; i < n; i++) {

			mp[vec[i - d]]--;

			if (mp[vec[i - d]] == 0) {
				sz--;
			}
			mp[vec[i]]++;
			if (mp[vec[i]] == 1) {
				sz++;
			}

			// cout << sz << " ";

			miin = min(miin, sz);

		}
		cout<<miin<<"\n";
	}

}

#include <vector>
#include <iostream>
#include <map>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--){
        int n,k,d;
        cin>>n>>k>>d;
        int a;
        vector<int> v;
        map<int,int> m;
        int s,ans=0;
        for(int i=0 ; i<d; i++){
            cin>>a;
            v.push_back(a);
            if(m[a]==0) ans++;
            m[a]++;
        }
        s=ans;
        int l=1;
        for(int i=d; i<n; i++){
            cin>>a;
            m[v[l-1]]--;

            if(m[v[l-1]]==0) s--;
            if(m[a]==0) s++;
            m[a]++;
            if(ans>s) ans=s;
            v.push_back(a);
            l++;
        }

        cout<<ans<<endl;
    }

}

#include <bits/stdc++.h>
using namespace std;
int a[1000005];
int main() {
	int t;
	cin>>t;
	while(t--)
	{
		memset(a,0,sizeof(a));
		int n,k,d;
		cin>>n>>k>>d;
		int arr[n];
		set<int> st;
		int minn=INT_MAX;
		int cnt=0;
		queue<int> q;
		for(int i=0;i<n;i++)
			cin>>arr[i];
		for(int i=0;i<n;i++)
		{
			if(cnt!=d)
			{
				cnt++;
				q.push(arr[i]);
				st.insert(arr[i]);
				a[arr[i]]++;
			}
			if(cnt==d)
			{
				int x=st.size();
				minn=min(minn,x);
				cnt--;
				int r=q.front();
				q.pop();
				if(a[r]==1)
				{
					st.erase(r);
					a[r]--;
				}
				else
				{
					a[r]--;
				}
			}
		}
		cout<<minn<<endl;
	}
	// your code goes here
	return 0;
}

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <unordered_map>
#include <random>
using namespace std;
#define CLR(a) memset(a, 0, sizeof a)
#define _unique(v) sort(v.begin(), v.end()), v.erase(unique(v.begin(), v.end()), v.end());
typedef long long ll;
template <class T>
T _pow(T a, T b, T mod);
template <class T>
inline void print(T x, T R = 10);
const int MAXN = 1e6 + 5;
template <typename T, typename... Types>
void in(T& x, Types& ... oth);
//------------------------head----------------------------
ll a[MAXN];
ll MAP[MAXN];
int32_t main()
{
	//freopen("1.in", "r", stdin);
	////32432532523543534
	int t;
	cin >> t;
	while (t--)
	{

		ll n, k, d;
		cin >> n >> k >> d;
		for (int i = 1; i <= n; i++)
		{
			cin >> a[i];
			MAP[a[i]] = 0;
		}
		ll MIN = 0;
		ll size = 0;
		for (int i = 1; i <= d; i++)
		{
			if (MAP[a[i]] == 0)MIN++;
			MAP[a[i]]++;
		}
		size = MIN;
		for (int i = d + 1; i <= n; i++)
		{

			if (MAP[a[i]] == 0)size++;
			MAP[a[i]]++;
			MAP[a[i - d]]--;
			if (MAP[a[i - d]] == 0)size--;
			MIN = min(MIN, size);
		}
		cout << MIN << endl;
	}

	return 0;
}

//-----------------------------------
template <typename T>
void in(T& x)
{
	static char ch;
	static bool neg;
	for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar())
		;
	for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar())
		;
	x = neg ? -x : x;
}
template <typename T, typename... Types>
void in(T& x, Types& ... oth)
{
	static char ch;
	static bool neg;
	for (ch = neg = 0; ch < '0' || '9' < ch; neg |= ch == '-', ch = getchar())
		;
	for (x = 0; '0' <= ch && ch <= '9'; (x *= 10) += ch - '0', ch = getchar())
		;
	x = neg ? -x : x;
	in(oth...);
}
template <class T>
T _pow(T a, T b, T mod)
{
	T base = a, res = 1;
	while (b)
	{
		if (b & 1)
			res = (res * base) % mod;
		base = (base * base) % mod;
		b >>= 1;
	}
	return res;
}
template <class T>
inline void print(T x, T R)
{
	if (x < 0)
	{
		putchar('-');
		x = -x;
	}
	if (x >= R)
		print(x / R, R);
	putchar(x % R + '0');
}

#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>

#ifdef _MSC_VER
#define getchar_unlocked _getchar_nolock
#endif

using std::cout;
using std::endl;
using std::cin;
using std::vector;
using std::string;
using std::set;
using std::pair;
using std::stack;
using std::queue;
using std::map;

#define ll long long
#define forall(m_it, m_con) for (auto m_it = m_con.begin(); m_it < m_con.end(); m_it++)

// ===== // ===== // ===== //
int read_int();
// ===== // ===== // ===== //
// ===== // ===== // ===== //
void func();
// ===== // ===== // ===== //
// ===== // ===== // ===== //

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int T;
	cin >> T;
	for (int i = 0; i < T; i++)
		func();

	return 0;
}

// ===== // ===== // ===== //

vector<int> a;
vector<int> vx;

void func()
{
	int n, k, d;
	cin >> n >> k >> d;
	if (a.size() < n)
		a.resize(n);
	_getchar_nolock();
	for (int i = 0; i < n; i++)
		a[i] = read_int() - 1;
	if (vx.size() < k)
		vx.resize(k);
	for (auto & it : vx)
		it = 0;
	int i, numb = 0;
	for (i = 0; i < d; i++)
	{
		if (vx[a[i]] == 0)
			numb++;
		vx[a[i]]++;
	}
	int min = numb;
	for (i = d; i < n; i++)
	{
		if (vx[a[i - d]] == 1)
			numb--;
		vx[a[i - d]]--;
		if (vx[a[i]] == 0)
			numb++;
		vx[a[i]]++;
		min = std::min(min, numb);
		if (min == 1)
		{
			cout << min << "\n";
			return;
		}
	}
	cout << min << "\n";
}

// ===== // ===== // ===== //
int read_int()
{
	char c;
	int ans = 0;
	c = _getchar_nolock();
	while (true)
	{
		if (c == '\n')
			return ans;
		if (c == ' ')
			return ans;
		ans *= 10;
		ans += c - '0';
		c = _getchar_nolock();
	}
}
// ===== // ===== // ===== //

#include <iostream>
#include <sstream>
using namespace std;
#include <bits/stdc++.h>
#include<utility>
#include <algorithm>
#include<iterator>
#define  go return 0
#define rep(i,n) for(int i=0;i<n;++i)
#define rep(j,m) for(int j=0;j<m;++j)
#define REP(i,n) for(int i=1;i<=n;++i)
#define all(v)   ((v).begin()), ((v).end())
#define len(s)   ((ll)s.size())
#define F first
#define S second
#define pb push_back
#define pf push_front
#define mp make_pair
typedef long long ll;
typedef double db;
typedef vector<ll> ve;
typedef vector<pair<int ,char> >vepa;
typedef set<char>se;
typedef map<ll ,ll> mpp;
const ll N=1e6+5 ,OO=1e18;
const int di[]={1,-1,0,0};
const int dj[]={0,0,1,-1};
ll TC,n,m,j,k,ans,cnt,arr[N],mn;
bool f,vis[N];
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
   cin>>TC;
   while(TC--){
     mpp mp;
     mn=1e9 , j=0;
     cin>>n>>m>>k;
     ll arr[n];
     rep(i,n&&cin>>arr[i]);
     rep(i,k)
       mp[arr[i]]++;
     mn=min(mn,len(mp));
     for(int i=k;i<n;i++)
     {
         mp[arr[i]]++;
         mp[arr[j]]--;
         if(mp[arr[j]]==0)
            mp.erase(arr[j]);
         mn=min(mn,len(mp));
        j++;
     }
     cout<<mn<<"\n";
   }
go;
}

#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t; cin>>t;
    for(int j=0 ; j<t ; j++){
    int n,k,d; cin>>n>>k>>d;
    int arr[n];   vector<int>v;
    for(int i=0 ; i<n ; i++){
        cin>>arr[i];
    }
    for(int i=0 ; i<n-d+1 ; i++){
             set<int>s;
     for(int h=i ; h<d+i ; h++){
        s.insert(arr[h]);
     }
    v.push_back(s.size());
    }
    cout<<*min_element(v.begin(),v.end())<<endl;
    }
}

#include <bits/stdc++.h>

using namespace std;

int main () {
    int t;
    cin >> t;
    for (int i = 0; i < t; ++i) {
        int n, k, d, an = 1e9;
        cin >> n >> k >> d;
        vector <int> a(n), s(k, 0);
        for (int j = 0; j < n; ++j) {
            cin >> a[j];
            if (j < d) {
                s[a[j] - 1]++;
            }
        }
        for (int j = 0; j < n - d + 1; ++j) {
            int p_an = 0;
            for (int q = 0; q < k; ++q) {
                if (s[q] > 0) {
                    p_an++;
                }
            }
            an = min(an, p_an);
            s[a[j] - 1]--;
            if (j != n - d) {
                s[a[j + d] - 1]++;
            }
        }
        cout << an << "\n";
    }
}

#include<bits/stdc++.h>
using namespace std;

#define ar(a,i,j) a[i][j]
#define arr(a,i,j,k) a[i][j][k]
#define FastIO ios::sync_with_stdio(false); cin.tie(nullptr);cout.tie(nullptr)
#define IN freopen("E:\\programming\\New folder\\input.txt","r+",stdin)
#define OUT freopen("E:\\programming\\New folder\\output.txt","w+",stdout)
#define inf 1e18
#define eps 1e-15
#define ll long long
#define nl printf("\n")
#define gap printf(" ")
#define in1(a) scanf("%I64d",&a)
#define in2(a,b) in1(a);in1(b)
#define in3(a,b,c) in2(a,b);in1(c)
#define in4(a,b,c,d) in2(a,b);in2(c,d)
#define ins(s) scanf("%s",&s)
#define out1(a) printf("%I64d",a)
#define out2(a,b) printf("%I64d %I64d",a,b)
#define out3(a,b,c) printf("%I64d %I64d %I64d",a,b,c)
#define outs(s) printf("%s",s)
#define ilup(i,a,n) for(ll i=a;i<=n;i++)
#define dlup(i,n,a) for(ll i=n;i>=a;i--)
#define setarray(arr,a,n,val) for(ll i = a; i <= n; i++)arr[i] = val;

void check(vector<ll>&a)
{
    ilup(i,0,a.size() -1 )
    {
        out1(a[i]);
        gap;
    }
    nl;
}

void check(ll a[],ll n)
{
    ilup(i,0,n-1)
    {
        out1(a[i]);
        gap;
    }
    nl;
}

#define MAX 200005

ll t,n,k,d,a[MAX],ans,c;

void solve(){
    map<ll,ll> mp;
    in3(n,k,d);ilup(i,1,n) in1(a[i]);
    ans = c = 0;
    ilup(i,1,d){
        if(!mp[a[i]]){
            ans++;
            c ++;
        }
        mp[a[i]] = i;

    }
    for(ll i = 1, j = d + 1;j <= n; j++, i++){
        if(mp[a[i]] < i + 1){
            c--; mp[a[i]] = 0;
        }
        if(mp[a[j]] == 0){
            c++;
        }
        mp[a[j]] = j;
        ans = min(c, ans);
        // out3(ans,0,0);nl;
    }
    out1(ans);nl;
}

int main(){
    FastIO;
    #ifndef ONLINE_JUDGE
    IN;OUT;
    #endif
    in1(t);while(t--)
    solve();
}

#include <bits/stdc++.h>
#define ll(i,r) for(int i=0;i<r;i++)
#define li long long int
#define pb push_back
using namespace std;
/*void prnt(map<li,li> mp)
{map<li,li> :: iterator it=mp.begin();
	for(;it!=mp.end();it++)cout<<it->first<<" "<<it->second<<endl;
}*/
int main()
{
int t;cin>>t;
while(t--)
{
	li n,k,d;cin>>n>>k>>d;
	map<li,li>mp;
	deque <li> q;

	ll(i,d)
	{li a;
		cin>>a;

			q.pb(a);
			if(mp.count(a))mp[a]+=1;
			else mp.insert({a,1});

	}
	li sr=mp.size();
		for(int i=d;i<n;i++)
		{li a;cin>>a;
	li trash=	q.front();q.pop_front();//cout<<trash<<endl<<"/*************/ "<<endl;
	q.pb(a);
		if(a!=trash)
		{
			mp[trash]-=1;//cout<<mp[trash]<<"trash value"<<endl;
			if(mp.count(a))mp[a]+=1;
			else mp.insert({a,1});
			if(mp[trash]==0)mp.erase(trash);

		}
		if(sr>mp.size())
			sr=mp.size();

		}
	//	prnt(mp);
	//	cout<<"////////////////////////////////////////////////////////////////////"<<endl;

	cout<<sr<<endl;
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t;
	cin>>t;
	int times=0;
	int n,k,d;
	while(times<t)
	{
		times++;
		cin>>n>>k>>d;
		int a[k+1],b[n],c,min;
		for(int i=0;i<n;i++)
		{
			cin>>b[i];
		}
		min=1000;
		for(int i=0;i<=n-d;i++)
		{
			for(int z=0;z<k+1;z++)
			{
				a[z]=0;
			}
			c=0;
			for(int j=0;j<d;j++)
			{
				if(a[b[i+j]]==0)
				{
					a[b[i+j]]++;
					c++;
				}
			}
			if(c<min)
			{
				min=c;
			}
		}
		cout<<min<<"\n";
	}

	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main()
{
    ll t;
    cin>>t;

    while(t--)
    {
        ll n,k,d;
        cin>>n>>k>>d;
        vector<ll> a(n);
        for(ll i=0;i<n;i++) cin>>a[i];
        // if(d==n)
        // {
        // 	set<ll> b;
        // 	for(ll i=0;i<n;i++) b.insert(a[i]);
        // 	cout<<b.size()<<endl;
        // }
        // else
        // {
	        map<ll,ll> vis;
	        set<ll> s;
	        // vector<ll> s(k+1);
	        // for(ll i=0;i<n;i++) cin>>a[i];

	        ll mi=INT_MAX;
	        ll size=0;
	        for(ll i=0;i<=d-1;i++)
	        {
	        	vis[a[i]]++;
	        }
	        for(ll i=0;i<=d-1;i++)
	        {
	        	s.insert(a[i]);
	        }
	        size=s.size();
	        mi = min(mi,size);
	        for(ll i=d;i<n;i++)
	        {
	        	vis[a[i-d]]--;
	            if (vis[a[i-d]] == 0) size--;
	            if (vis[a[i]] == 0) size++;
	            vis[a[i]]++;
	            mi = min(size, mi);
	        }
	        cout<<mi<<endl;
	    // }
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,d,c,sum=0;
		cin>>n>>k>>d;
		vector<int>v,w;
		v.push_back(0);
		map<int,int>m;
		for(int i=1;i<=n;i++)
		{
			cin>>c;
			if(m[c]!=0)
			m[c]=0;
			v.push_back(c);
		}
		for(int i=1;i<=d;i++)
		{
			if(m[v[i]]==0)
			{
				sum++;
			}
				m[v[i]]++;
		}
		w.push_back(sum);
		for(int i=d+1;i<=n;i++)
		{
			if(m[v[i]]==0)
			sum++;
			m[v[i]]++;
			if(m[v[i-d]]==1)
			sum--;
			m[v[i-d]]--;
			w.push_back(sum);
		}
		w.push_back(sum);
		sort(w.begin(),w.end());
		cout<<w[0]<<"\n";
	}
}

#include <bits/stdc++.h>

using namespace std;

const int maxn = 2e5 + 20, maxk = 1e6 + 20;
int t, a[maxn], n, k, d, mokh[maxk], ans, g;

int main() {
	cin >> t;
	for (int o = 0; o < t; o++) {
		cin >> n >> k >> d;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < d; i++) {
			if (mokh[a[i]] == 0) {
				g++;
			}
			mokh[a[i]] += 1;
		}
		ans = g;
		for (int i = 1; i < n - d + 1; i++) {
			mokh[a[i - 1]] -= 1;
			if (mokh[a[i - 1]] == 0) {
				g--;
			}
			if (mokh[a[i + d - 1]] == 0) {
				g++;
			}
			mokh[a[i + d - 1]] += 1;
			ans = min (ans, g);
		}
		cout << ans << endl;
		g = 0;
		ans = 0;
		memset (mokh, 0, sizeof (mokh));
		memset (a, 0, sizeof (a));
	}
	return 0;
}

#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <queue>
#include <stack>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <fstream>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <immintrin.h>
#define rev(m) reverse(m.begin(),m.end())
#define met(a) memset(a,0,sizeof(a))
#define mpy(a,b) memcpy(a,b,sizeof(b))
#define sca(a) scanf("%d",&a)
#define scal(a) scanf("%lld",&a)
#define ls(x) t[x].l
#define rs(x) t[x].r
#define lb(i) i&-i
#define IT set<node>::iterator
#define PP pair<char,int>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
const int N = 1000010;
const int inf = INT_MAX;
const double eps = 1e-9;
const ull strmod = 212370440130137957ll;
const ull strp = 1e9 + 9;
inline int ymax(int a, int b) { return a > b ? a : b; }
inline int ymin(int a, int b) { return a < b ? a : b; }
int a[200005];
int v[N];
int n, m, k;
int main()
{
	int k, d, n, t;
	sca(t);
	while (t--)
	{
		sca(n), sca(k), sca(d);
		int ans = inf, res = 0;
		fill(v, v + k + 5, 0);
		for (int i = 1; i <= n; i++)
		{
			sca(a[i]);
			if (!v[a[i]])res++;
			v[a[i]]++;
			if (i > d)
			{
				v[a[i-d]]--;
				if (!v[a[i - d]])res--;
				ans = min(ans, res);
			}
			if (i == d)
				ans = min(ans, res);
		}
		printf("%d\n", ans);
	}
}

/*

4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4

*/

#include <bits/stdc++.h>

using namespace std;

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
  bool first = true;
  string res = "{";
  for (int i = 0; i < static_cast<int>(v.size()); i++) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(v[i]);
  }
  res += "}";
  return res;
}

template <size_t N>
string to_string(bitset<N> v) {
  string res = "";
  for (size_t i = 0; i < N; i++) {
    res += static_cast<char>('0' + v[i]);
  }
  return res;
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
  return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#endif

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;

#define mp make_pair
#define pb push_back

void solve() {
  int n, k, d;
  cin >> n >> k >> d;
  vector<int> a(n);
  for (int i = 0 ; i < n ; i++) {
    cin >> a[i];
  }
  map<int, int> cnt;
  int subs = 0;
  for (int i = 0 ; i < d ; i++) {
    cnt[a[i]]++;
    if (cnt[a[i]] == 1) {
      subs++;
    }
  }
  int res = subs;
  for (int i = d ; i < n ; i++) {
    cnt[a[i - d]]--;
    if (cnt[a[i - d]] == 0) subs--;
    cnt[a[i]]++;
    if (cnt[a[i]] == 1) subs++;
    res = min(res, subs);
  }
  cout << res << "\n";

}

int main() {
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }

  return 0;
}

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
const ll maxn = 1e7+7;
ll q,n,k,d;
ll a[maxn],b[maxn];
ll ans = 0;
int main(void){
	scanf("%lld",&q);
	while(q--){
		scanf("%lld %lld %lld",&n,&k,&d);
//		fill(a,a+1+n,0);
//		fill(b,b+1+n,0);
		ll ans = 0;
		for(int i = 1;i<=n;++i){
			scanf("%lld",&a[i]);
			if(i<=d){
				if(b[a[i]] == 0) ans += 1;
				b[a[i]] += 1;
			}
		}
		ll temp = ans;
		if(ans != 1){
			for(int i = d+1,j = 1;i<=n;++i,++j){
				b[a[j]] -= 1;
				if(b[a[j]] == 0) ans-=1;
				b[a[i]] += 1;
				if(b[a[i]] == 1) ans+=1;
				temp = min(temp,ans);
			}
			printf("%lld\n",temp);
		}else printf("%lld\n",ans);
		for(int i = 1;i<=n;++i)
			b[a[i]] = 0;
	}
	return 0;
}

/*   One_Eye_Ghoul           */

/* Slow and steady passes system testing : ) */
#include <stdio.h>
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define loop(i,n) for(i64 i=0; i<(n); ++i)
#define loop1(i,n) for(i64 i=1; i<=(n); ++i)
#define rloop(i,n) for(i64 i=(n)-1; i>=0; --i)
#define rloop1(i,n) for(i64 i=(n); i>0; --i)
#define loopit(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define xx first
#define yy second
#define pb push_back
#define eb emplace_back
#define mp std::make_pair

/**Define memory set function**/
#define mem(x,y) memset(x,y,sizeof(x))
#define CLEAR(x) memset(x,0,sizeof(x))

/**Define function and object**/
#define pb push_back
#define Sort(v) sort(v.begin(),v.end())
#define RSort(v) sort(v.rbegin(),v.rend())
#define CSort(v,C) sort(v.begin(),v.end(),C)
#define sqr(x) ((x)*(x))
#define find_dist(a,b) sqrt(sqr(a.x-b.x)+sqr(a.y-b.y))

/**Define constant value**/
#define ERR 1e-9
#define pi (2*acos(0))
#define PI 3.141592653589793

const long long INF = (1LL<<45LL);
const long long MAXLL = 9223372036854775807LL;
const unsigned long long MAXULL = 18446744073709551615LLU;
const long long MOD = 1000000007;
const long double DELTA = 0.000000001L;

typedef long long i64;
typedef unsigned long long ui64;
typedef std::pair<i64, i64> pii;
typedef std::vector<i64> vi;
typedef std::vector< std::vector<i64> > matrix;

i64 mpow(i64 x,i64 n1) { i64 ret=1; while(n1>0) { if(n1%2==1) ret=ret*x%MOD; x=x*x%MOD; n1/=2; } return ret; }
i64 inverse(i64 x) { return mpow(x,MOD-2); }

i64 dx[4]={0,0,1,-1};
i64 dy[4]={1,-1,0,0};

i64 B[200005];

map<i64,i64>mp1;

int main() {
	std::ios_base::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	////////////////////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	i64 t;
	cin>>t;

	while(t--){

		i64 n,k,d;
		cin>>n>>k>>d;

		loop(i,n)cin>>B[i];

		mp1.clear();
		i64 cnt=0,mn=k;

		for(i64 i=0;i<d;i++){
			if(mp1[B[i]]==0){
				cnt++;

			}
			mp1[B[i]]++;
		}
		mn=cnt;

		//cout<<mn<<" ";
		for(i64 i=d;i<n;i++){

			if(mp1[B[i-d]]==1){
				cnt--;
			}
			mp1[B[i-d]]--;
			if(mp1[B[i]]==0){
				cnt++;
			}
			mp1[B[i]]++;
			mn=min(mn,cnt);
		}
		cout<<mn<<endl;
	}

	return 0;
}

#include<bits/stdc++.h>

#define  debug(x)         cout << '>' << #x << ':' << x << endl;
#define  fo(i,n)          for(ll i=0;i<n;i++)
#define  unq(vec)         sort(all(vec)); vec.resize(unique(all(vec)) - vec.begin());
#define  era(v)           sort(v.begin(), v.end());v.erase(unique(v.begin(), v.end()), v.end());
#define  removethis(v,a)  v.erase(remove(v.begin(),v.end(), a), v.end());
#define  pb               push_back
#define  mp               make_pair
#define  endl             '\n'
#define  fi               first
#define  se               second

using namespace std;
typedef long long          ll;

//ll gcd(ll a, ll b) {return !b ? a : gcd(b, a % b);}
//ll lcm(ll a, ll b) {return (a / gcd(a, b)) * b;}
//ll modpow(ll a, ll b, ll m = MOD){a %= m; ll res = 1; while (b) {if (b & 1)res = (res * a) % m; a = (a * a) % m; b >>= 1;} return res;}
//ll bpow(ll a, ll b){ll res = 1; while (b) {if (b & 1)res = res * a; a = a * a; b >>= 1;} return res;}
//ll modinv(ll a, ll m = MOD) {return modpow(a, m - 2, m);}
const ll MOD = 1e9 + 7;
//const double PI  = acos(-1.0);
//const double EPS = (1e-10);
//const int dx4[4] = {0, 1, 0, -1};
//const int dy4[4] = { -1, 0, 1, 0};
//const int dx8[8] = { -1, -1, -1, 0, 1, 1, 1, 0};
//const int dy8[8] = { -1, 0, 1, 1, 1, 0, -1, -1};
bool cmp(int X, int Y) {return X > Y;}
//int dcp(double A, double B){return fabs(A-B)<=EPS ? 0 : A<B ? -1:1;}
bool ccp(const pair<string, int> a,const pair<string, int> b){
return a.second<b.second;
}

int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll t;cin>>t;
while(t--){
    ll n,k,d;cin>>n>>k>>d;
    ll a[n+1];

    ll ans = MOD;
    for(ll i = 1;i<=n;i++){cin>>a[i];}
    for(ll i = 1; i<=(n - d +1); i++){
            set<ll>s;
        for(ll j = i; j<(i+d); j++){
            s.insert(a[j]);
        }
    ans = min(ans,(ll)s.size());
    }
   cout<<ans<<endl;
}
}

#include<bits/stdc++.h>
using namespace std;

int b[1001000];
int a[1001000];

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        int n,k,d;
        memset(b,0,sizeof b);
        memset(a,0,sizeof a);
        scanf("%d%d%d",&n,&k,&d);
        int x;
        for(int i=0;i<n;i++){
            scanf("%d",&a[i]);
        }
        int ans=0x3f3f3f;
        int l=0,r=0;
        int cnt=0;
        while(r<n){
            b[a[r]]++;
            if(b[a[r]]==1)cnt++;
            r++;
            if(r-l==d){
                ans=min(ans,cnt);
                if(b[a[l]]==1) cnt--;
                b[a[l]]--;
                l++;
            }

        }
        printf("%d\n",ans);
    }
    return 0;
}

#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
using namespace std;
typedef long long ll;
int vis[1001010];
int a[1001010];
int T,n,k,d;
int main()
{
	scanf("%d",&T);
	while(T --){
		memset(vis,0,sizeof vis);
		scanf("%d%d%d",&n,&k,&d);
		int ans = 1e9 + 7,sum = 0;
		for(int i = 1;i <= n ;i ++){
			scanf("%d",&a[i]);

			if(i > d){
				vis[a[i - d]] --;
				if(vis[a[i - d]] == 0)sum --;
			}
			if(vis[a[i]] == 0)sum ++;
			vis[a[i]] ++;
			if(i >= d)ans = min(ans,sum);
		}
		cout<<ans<<endl;
	}
	return 0;
}
/*
long long
线段树四倍
写代码时请注意:
	1.是否要开Long Long?数组边界处理好了么?
	2.实数精度有没有处理?
	3.特殊情况处理好了么?
	4.做一些总比不做好.
思考提醒:
	1.最大值和最小值问题可不可以用二分答案?
	2.有没有贪心策略?否则能不能dp?
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define r0 return 0
int main()
{
    ll t,z,n,k,d,i,j,s,smin,a[200007],ans[10007];
    map <ll,ll> u;
    cin>>t;
    for(z=1;z<=t;z++)
    {
        cin>>n>>k>>d;
        for(i=1;i<=n;i++)
        cin>>a[i];
        s=0;
        smin=INT_MAX;
        for(i=1;i<=n;i++)
        {
            if(i>d && a[i]==a[i-d])
                continue;
            if(u[a[i]]==0)
                s++;
            u[a[i]]++;
            if(i>d)
            {
                u[a[i-d]]--;
                if(u[a[i-d]]==0)
                    s--;
            }
            if(i>=d)
                smin=min(s,smin);
        }
        ans[z]=smin;
        u.clear();
    }
    for(i=1;i<=t;i++)
        cout<<ans[i]<<"\n";
}

#include<iostream>
#include<map>
using namespace std;

int main()
{
    int t,j;
    cin>>t;
    for(j=0;j<t;j=j+1)
    {
	long long int n,min=0,l,i,k,d,x;
	cin>>n>>k>>d;
	long long int a[n];
	map<int,int>m;
	for(i=0;i<n;i=i+1)
	{
		cin>>a[i];
	}
	for(i=0;i<d;i=i+1)
	{
	    x=a[i];
	    m[x]=m[x]+1;
	}
	min=m.size();
    l=min;
	for(i=d;i<n;i=i+1)
	{
	    x=a[i];
		if(m[x]==0)
		 {l=l+1;}
		 m[x]=m[x]+1;

       x=a[i-d];
		if(m[x]==1)
		{l=l-1;}
       m[x]=m[x]-1;

       if(l<min)
        {min=l;}

	}
	cout<<min<<endl;
    }

}

#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<queue>
#pragma warning(disable:4996)
#include<cstdio>
#include<cstring>
using namespace std;
int a[1000], b[1000];
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, k, d, ans = 0, an = 0;
		cin >> n >> k >> d;
		memset(b, 0, sizeof(b));
		for (int i = 0; i < n; i++)cin >> a[i];
		for (int i = 0; i < d; i++) {
			if (b[a[i]] == 0)ans++;
			b[a[i]]++;
		}
		an = ans;
		for (int i = d; i < n; i++) {
			if (a[i] == a[i - d]);
			else {
				if (b[a[i]] == 0)ans++;
				if (b[a[i - d]] == 1)ans--;
			}
			an = min(an, ans);
			b[a[i]]++;
			b[a[i - d]]--;
		}
		cout << an << endl;
	}
	return 0;
}

#include <bits/stdc++.h>
#include<algorithm>
using namespace std;
#define f(i,a,b) for(int i=a;i<b;i++)
#define f_(i,a,b) for(int i=a;i>=b;i--)
long long q,n,k,d,p1,p2,m,mn,a[200099];
int main(){
	cin>>q;
	f(salam,0,q){
		cin>>n>>k>>d;
		map <int,int> mark;
		p1=0,p2=0,m=0,mn=1e9;
		f(i,0,n)
			scanf("%I64d",&a[i]);
		f(i,0,d){
			if(mark[a[p2]]==0)
				m++;
			mark[a[p2]]++;
			p2++;
		}
		mn=m;
		while(p2<n){
			if(mark[a[p1]]==1)
				m--;
			mark[a[p1]]--;
			p1++;
			if(mark[a[p2]]==0)
				m++;
			mark[a[p2]]++;
			p2++;
			mn=min(mn,m);
		}
		while(p1<n){
			mark[a[p1]]--;
			p1++;
		}
		//cout<<salam<<" : "<<endl;
		//f(i,0,10){
		//	cout<<mark[i];
		//}
		//cout<<endl;
		cout<<mn<<endl;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,ll>mp;
ll ar[1234567];

int main()
{
    ll t,n,m,a,b,c,ok=0,ans,res,k,i;
    cin>>t;
    while(t--)
    {
        ans=1e9;
        ok=0;
        cin>>n>>m>>k;
        for(i=1; i<=n; i++)
        {
            cin>>ar[i];
        }
        for(i=1; i<=k; i++){
            mp[ar[i]]++;
            if(mp[ar[i]]==1)ok++;
        }
        ans=min(ans,ok);
        for(i=k+1; i<=n; i++)
        {
            mp[ar[i-k]]--;
            if(mp[ar[i-k]]==0)ok--;
            mp[ar[i]]++;
            if(mp[ar[i]]==1){ok++;}
            ans=min(ans,ok);
        }
        cout<<ans<<endl;
        mp.clear();

    }
}

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main(){
	ll t;
	cin>>t;
	while(t--){
	ll n,k,d;
	cin>>n>>k>>d;
	ll *arr=new ll[n];
	for(ll i=0;i<n;i++){
		cin>>arr[i];
	}
	map<ll,ll>mp;
	ll min=0;
	for(ll i=0;i<d;i++){
		if(mp.find(arr[i])!=mp.end()){
			mp[arr[i]]++;
		}
		else{
			mp[arr[i]]=1;
			min++;
		}
	}
	ll count=min;
	for(ll i=d;i<n;i++){
	//	cout<<count<<" ";
	//	cout<<mp[3]<<arr[i]<<" ";
		if(mp[arr[i-d]]==1){
			count--;
			mp[arr[i-d]]=0;
		}
		else{
			mp[arr[i-d]]--;
		}

		if(mp.find(arr[i])!=mp.end()){

			if(mp[arr[i]]==0){
			//	cout<<count<<" ";
					count++;

			}

			mp[arr[i]]++;
	//		cout<<"hi";
		}
		else{
			count++;
			mp[arr[i]]=1;
		}
		if(count<min){
			min=count;
		}
	}

cout<<min<<endl;
}
}

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <vector>
using namespace std;

int main(){
//    freopen("input.txt", "rt", stdin);
  //  freopen("output.txt", "wt", stdout);
    int a[1000001] = {0}, aa[1000001], n, k, d, t, min, sum = 0;
    cin >> t;
    for (int i = 0; i < t; i++) {
        cin >> n >> k >> d;
        min = k;
        for (int j = 0; j < n; j++) {
            cin >> aa[j];
        }
        for (int j = d; j <= n; j++) {
            if (j == d){
                for (int r = 0; r < d; r++) {
                    if (a[aa[r]] == 0) {
                        sum++;
                    }
                    a[aa[r]]++;
                }
            } else {
                a[aa[j - d - 1]]--;
                a[aa[j - 1]]++;
                if (a[aa[j - d - 1]] == 0) {
                    sum--;
                }
                if (a[aa[j - 1]] == 1 && aa[j - 1] != aa[j -  d - 1]) {
                    sum++;
                }
            }
            if (min > sum) {
                min = sum;
            }
        }
        sum = 0;
        for (int j = 0; j <= k; j++) {
            a[j] = 0;
        }
        cout << min << endl;
    }
}

#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
using namespace std;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin >> t;
	for (int f = 0; f < t; f++) {

		int n, k, d;
		cin >> n >> k >> d;

		vector<int> a;
		for (int i = 0; i < n; i++) {
			int h;
			cin >> h;
			a.push_back(h);

		}
		int i = 0;
		int j = 0;
		map<int, int> m;
		int ans=10000000;
		int s = 0;
		while (j < d) {
			if (m[a[j]] == 0)s++;
			m[a[j]]++;
			j++;
		}
		while ( j < n) {
			ans = min(ans, s);
			m[a[i]]--;
			if (m[a[i]] == 0) s--;
			i++;

			if (m[a[j]] == 0) s++;
			m[a[j]]++;
			j++;
		}
		ans = min(ans, s);
		cout << ans << '\n';
	}
	return 0;
}

#include <bits/stdc++.h>
#define SPEED std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0);
using namespace std;

int main(){
    SPEED;

    int casos;
    cin >> casos;
    for (int i = 0; i < casos; i++){
    	int n, k, d, min = 100, x;

    	cin >> n >> k >> d;
    	vector<int> ln;
    	for (int j = 0; j < n; j++){
    		cin >> x;
    		ln.push_back(x);
    	}
    	for (int j = 0; j <= n-d; j++){
    		set<int> arrmin(ln.begin()+j, ln.begin()+j+d);
    		if (arrmin.size() < min){
    			min = arrmin.size();
    		}
    	}
    	cout << min << '\n';
    }

    return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k,d;
int a[311111];
int b[1111111];
bool check(int x)
{
    int l = 1,r=1;
    int cost=1;
    b[a[1]]=1;
    while (r<=n)
    {
        if (cost > x) {
            while (cost > x) {
                b[a[l]]--;
                if (b[a[l]] == 0) {
                    cost--;
                }
                l++;
            }
        } else{

            if (r-l+1>=d)
            {
                for (int i=l;i<=r;i++)
                {
                    b[a[i]]=0;
                }
               return true;
            }
            r++;
            if (b[a[r]]==0)
            {
                cost++;
            }
            b[a[r]]++;
        }
    }
    for (int i=l;i<=r;i++) b[a[i]]=0;
    return false;

}
int main() {
    int T;
    scanf("%d",&T);
    while (T--) {
        scanf("%d%d%d", &n, &k, &d);
        for (int i = 1; i <= n; i++) {
            scanf("%d",&a[i]);
        }
        int l=0,r=n,mid=0;
        while (l+1<r)
        {
            mid = (l+r)/2;
            if (check(mid)) r=mid;
            else l=mid;
        }
        printf("%d\n",r);
        for (int i = 1;i<=n;i++) b[a[i]]=0;
    }
}

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
        int n, k, d;
        cin>>n>>k>>d;
        int ar[n];
        for(int i=0;i<n;i++){
            cin>>ar[i];
        }
        vector<int> v;
        for(int i=0;i<=n-d;i++){
            int c=0;
            int freq[k+1];
            memset(freq, 0, sizeof(freq));
            for(int j=i;j<i+d;j++){
                freq[ar[j]]++;
            }
            for(int j=1;j<=k;j++){
                if(freq[j]>0){
                    c++;
                }
            }
            v.push_back(c);
        }
        int l= v.size();
        int min=v[0];
        for(int i=1;i<l;i++){
            if(v[i]<min){
                min= v[i];
            }
        }
        cout<<min<<endl;
    }
}

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
int a[maxn];
int vis[200007];
int main() {
	int t;
	cin >> t;
	while (t--) {
		memset(vis, 0, sizeof(vis));
		int n, k, d;
		cin >> n >> k >> d;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, ans = 0;
		for (int i = 0; i < d; i++) {
			if (!vis[a[i]]) {
				sum++;
			}
			vis[a[i]]++;
		}
		ans = sum;
		int j = 0,i = 1;
		for (i = 1, j = d; j < n; i++, j++) {
			//cout << i << " " << j <<" "<<sum<< " md" << endl;
			vis[a[i - 1]]--;
			if (!vis[a[i - 1]])sum--;
			if (!vis[a[j]])sum++;
			vis[a[j]]++;
			if (sum < ans)ans = sum;
		}
		cout << ans << endl;
	}
}

#include <iostream>
#include <vector>
#include <map>
using namespace std;

int main() {
	int t;
	cin >> t;

	while (t--) {
		int n, k, d;
		cin >> n >> k >> d;

		vector<int> episodes(n, 0);

		for (int i = 0; i < n; ++i) {
			cin >> episodes[i];
		}

		int minimum_shows_to_buy = numeric_limits<int>::max();

		int current_index = 0;
		int start_index = 0;
		int current_days = 0;

		map<int, int> current_bought;

		while (current_index < n) {
            ++current_days;

            ++current_bought[episodes[current_index]];

			if (current_days == d) {
                if (current_bought.size() < minimum_shows_to_buy) {
                    minimum_shows_to_buy = current_bought.size();
                }

				--current_bought[episodes[start_index]];

				if (current_bought[episodes[start_index]] == 0)
					current_bought.erase(episodes[start_index]);

				++start_index;
				--current_days;
			}

			++current_index;
		}

        cout << minimum_shows_to_buy << endl;
    }

    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endll '\n'
#define C getchar()
using ll = long long;
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pii pair<int, int>
const int MAXN = 1e6 + 10;
#define stop system("pause")
#define lowbit(x) ((x) & (-x))
#define Temp template <typename T>
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
Temp inline void rd(T &s)
{
	s = 0;
	T t = 1, k = C;
	for (; k < '0' || k > '9'; k = C)
		if (k == '-')
			t = -1;
	for (; k >= '0' && k <= '9'; k = C)
		s = (s << 1) + (s << 3) + (k ^ 48);
	s *= t;
}

int vis[MAXN];
int a[MAXN];
int main()
{
	int t;
	rd(t);
	while (t--)
	{
		mem(vis, 0);
		int n, k, d, ans = 0;
		rd(n),rd(k),rd(d);
		int i, owa = 0;
		for (i = 0; i < n; i++)
			rd(a[i]);
		for (i = 0; i < d; i++)
		{
			if (vis[a[i]] == 0)
			{
				ans++;
				owa++;
			}
			vis[a[i]]++;
		}
		int x = 0;
		while (i < n)
		{
			x++;
			if (--vis[a[x - 1]] == 0)
				owa--;
			if (vis[a[i]]++ == 0)
				owa++;
			if (owa < ans)
				ans = owa;
			i++;
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <iostream>
#include <set>
#include <algorithm>
using namespace std;

int s[105];

int main() {
	int q;
	cin >> q;
	for (int k = 0; k < q; k++) {
		int n, e, d;
		cin >> n >> e >> d;

		for (int i = 0; i < n; i++) {
			cin >> s[i];
		}

		int res = e;

		for (int i = 0; i <= n - d; i++) {
			set<int> a;
			for (int j = i; j < i + d; j++) {
				a.insert(s[j]);
			}
			res = min(res, static_cast<int>(a.size()));
		}

		cout << res << endl;
	}
}

#include<bits/stdc++.h>

using namespace std;
const int MAXN = 1e6 + 10;
int cnt[MAXN];
int a[MAXN];
int main()
{
    int cas, n, k, d;
    scanf("%d", &cas);
    while (cas--) {
        scanf("%d%d%d", &n, &k, &d);
        int ans = d, num = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%d", &a[i]);
            cnt[a[i]]++;
            if (cnt[a[i]] == 1) num++;
            if (i > d) {
                if ((--cnt[a[i - d]]) == 0)
                    num--;
            }
            if (i >= d) ans = min(ans, num);
        }
        for (int i = 1; i <= n; i++)
            cnt[a[i]] = 0;
        printf("%d\n",ans);
    }
}

#include <bits/stdc++.h>
using namespace std;
set <int> st;
int b[1000005];
int main()
{
	ios::sync_with_stdio(0);
		int q;
	   cin>>q;
	   for(int i=0; i<q; i++){
	   	int n,k,d;
	   	cin>>n>>k>>d;

	   	int a[n];
	   	for(int j=0; j<n; j++){
	   		cin>>a[j];
		}
		int ans=0,minn=INT_MAX;

		for(int j=0; j<d; j++){
			st.insert(a[j]);
			b[a[j]]++;
		}

		minn=st.size();

		for(int l=0; l<n-d; l++){
			//cout<<st.size()<<" 1   l="<<l+1<<endl;
			b[a[l]]--;

			if(b[a[l]] == 0){
				st.erase(a[l]);
			}
			//cout<<st.size()<<" 2"<<endl;
			st.insert(a[l+d]);
			b[a[l+d]]++;
			//cout<<st.size()<<" a[l+d]="<<a[l+d]<<endl;
			ans=st.size();
			minn=min(minn,ans);
		}
		cout<<minn<<endl;
		st.erase(st.begin(),st.end());
		for(int j=0; j<100005; j++){
		    b[j]=0;
		}
		//cout<<st.size()<<" 4"<<endl<<endl;
	}
	return 0;

}

#include<bits/stdc++.h>
using namespace std;
const int maxn = 300000 + 10;
int a[maxn], v[maxn], rt[maxn], vis[(int)1e6 + 10], tot, n;
struct node
{
	int ls, rs, sum;
	node(int ls = 0, int rs = 0, int sum = 0)
	{
		this->ls = ls;
		this->rs = rs;
		this->sum = sum;
	}
}tree[maxn * 30];
int build1(int l, int r)
{
	int t = ++tot;
	tree[t].sum = 0;
	if (l != r)
	{
		int mid = (l + r) >> 1;
		tree[t].ls = build1(l, mid);
		tree[t].rs = build1(mid + 1, r);
	}
	return t;
}
int build2(int l, int r, int last, int pos, int val)
{
	int t = ++tot;
	tree[t] = tree[last];
	tree[t].sum += val;
	if (l != r)
	{
		int mid = (l + r) >> 1;
		if (pos <= mid)
			tree[t].ls = build2(l, mid, tree[last].ls, pos, val);
		else
			tree[t].rs = build2(mid + 1, r, tree[last].rs, pos, val);
	}
	return t;
}
int query(int L, int R, int l, int r, int t)
{
	if (l <= L && r >= R)
		return tree[t].sum;
	int mid = (L + R) >> 1, ans = 0;
	if (r <= mid)
		ans += query(L, mid, l, r, tree[t].ls);
	else
		if (l > mid)
			ans += query(mid + 1, R, l, r, tree[t].rs);
		else
		{
			ans += query(L, mid, l, r, tree[t].ls);
			ans += query(mid + 1, R, l, r, tree[t].rs);
		}
	return ans;
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		memset(vis, 0, sizeof(vis));
		memset(a, 0, sizeof(a));
		memset(v, 0, sizeof(v));
		int n, k, d;
		int ans = 0x3f3f3f3f;
		cin >> n >> k >> d;
		for (int i = 1; i <= n; i++) {
			cin >> a[i];
		}
		rt[0] = build1(1, n);
		for (int i = 1; i <= n; i++)
		{
			if (!vis[a[i]])
				rt[i] = build2(1, n, rt[i - 1], i, 1);
			else
			{
				rt[i] = build2(1, n, rt[i - 1], vis[a[i]], -1);
				rt[i] = build2(1, n, rt[i], i, 1);
			}
			vis[a[i]] = i;
		}
		for (int i = 1, j = d; j <= n; i++, j++) {
			int lin = query(1, n, i, j, rt[j]);
			if (lin < ans)ans = lin;
		}
		cout << ans << endl;
	}

	return 0;
}

#include <bits/stdc++.h>

using namespace std;

void initialise (int a[] , int k)
{
      for(int i=0  ; i<k ; i++)
            a[i] = 0;
}

void show_vector(vector<int> v)
{
      for(int i=0 ; i<v.size() ; i++)
      {
            cout << v[i] << "\t";
      }
}

int main()
{
      int t;
      cin >> t;
      int n , k , d;
      int num;

      vector <int> output;
      int aux[101];

      while(t>0)
      {
            vector <int> input;
            int count = 0;
            //int min_count = 0;
            cin >> n >> k >> d;
            initialise(aux , k);

            /*for(int i=0 ; i<k ;i++)
            {
                  cout << aux[i] << "\t";
            }
            cout << endl;*/

            for(int i=0 ; i<n ; i++)
            {
                  cin >> num;
                  input.push_back(num);
            }

            for(int j=0 ; j<d ; j++)
            {
                  if(aux[input[j]-1] == 0)
                  {
                        count++;
                  }
                  aux[input[j]-1]++;
            }

            //cout << "\n"<< "Initial:- " << count;
            //cout << endl;

            /*for(int i=0 ; i<k ;i++)
            {
                  cout << aux[i] << "\t";
            }
            cout << endl;*/

            int in;
            int out;

            int min_count = count;

            for(int i=0 ; i<=n-d-1; i++)
            {
                  out = i;
                  in = i+d;
                  //cout << aux[input[in]-1];

                  if(input[in] != input[out])
                  {
                        if(aux[input[in]-1]!=0)
                              count+=0;
                        if(aux[input[in]-1] == 0)
                              count+=1;
                        if(aux[input[out]-1]==1)
                              count-=1;
                        if(aux[input[out]-1]>1)
                              count-=0;
                  }
                  else
                        count+=0;

                  //cout << i <<"count :- " <<count << endl;
                  min_count = min(min_count , count);
                  //cout <<"min_ count :- " <<min_count << endl << endl;

                  /*if(i>=5)
                  {
                        for(int i=0 ; i<k ;i++)
                        {
                              cout << aux[i] << "\t";
                        }
                        cout << endl;
                  }*/

                  aux[input[in]-1]++;
                  aux[input[out]-1]--;
            }
            //cout << "Final :- "<< min_count << endl;
            output.push_back(min_count);
            t--;
      }
      for(int i=0 ; i<output.size() ; i++)
            cout << output[i] << endl;
}

#include <iostream>
#include "bits/stdc++.h"
#include <vector>

using namespace std;

int main()
{
    int t;
    cin >> t;
    for(int q = 0; q < t; q++)
    {

    int n, k, d;
    cin >> n >> k >> d;

    vector<int> a;
    vector<vector<int> > bl;

    a.clear();
    bl.clear();

    for(int i = 0; i < n; i++)
    {
        int x;
        cin >> x;
        a.push_back(x);
    }

    //разделяем сериалы на блоки
    for(int i = 0; i < n - d+1; i++)
    {
        vector<int> vec;
        vec.clear();
        bl.push_back(vec);
        for(int j = i; j < d + i; j++)
        {
            bl[i].push_back(a[j]);
        }
    }
    int res = 1e9;

    //сортируем номера сериалов в блоке
    for(int i = 0; i < bl.size(); i++)
    {
        sort(bl[i].begin(), bl[i].end());

        int kol = 0;
        for(int j = 0; j < bl[i].size()-1; j++)
        {
            if(bl[i][j] != bl[i][j+1])
            {
                kol++;
            }
        }

        res = min(res, kol);
    }

    //считаем количество разных сериалов
    //for(int i = 0; i < bl.size(); i++)
    //{
    //}
    cout << res + 1 << endl;
    }
    return 0;

}

#include <iostream>

using namespace std;

int a[2000005];

int main()
{
	int t; cin>>t;
	while (t--)
	{
	            int n, k, d;
	            cin>>n>>k>>d;
	            int kol[1000005]={};
	            for (int i=1; i<=n; i++) {
	                        cin>>a[i];
	            }
	            int ans=0;
	            for (int i=1; i<=d; i++) {
	                        kol[a[i]]++;
	                        if (kol[a[i]]==1) ans++;
	            }
	            int temp=ans;
	            for (int i=d+1; i<=n; i++) {
	                        kol[a[i]]++;
	                        if (kol[a[i]]==1) temp++;
	                        kol[a[i-d]]--;
	                        if (kol[a[i-d]]==0) temp--;
	                        ans=min(ans, temp);
	            }
	            cout<<ans<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define N 1000005
using namespace std;

int n,a[N],vis[N],cnt,k,d;

inline int read()
{
	int ans=0,f=1;char c=getchar();
	while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
	while(c>='0'&&c<='9') ans=(ans<<1)+(ans<<3)+(c^48),c=getchar();
	return ans*f;
}

int main()
{
	int t=read();
	while(t--)
	{
		n=read(),k=read(),d=read();
		for(int i=1;i<=n;++i) a[i]=read();
		for(int i=1;i<=k;++i) vis[i]=0;
		cnt=0;
		int ans=k;
		for(int i=1;i<=d;++i)
		{
			if(!vis[a[i]]) cnt++;
			vis[a[i]]++;
		}
		ans=min(ans,cnt);
		for(int i=d+1;i<=n;++i)
		{
			if(vis[a[i-d]]==1) cnt--;
			vis[a[i-d]]--;
			if(vis[a[i]]==0) cnt++;
			vis[a[i]]++;
			ans=min(ans,cnt);
		}
		printf("%d\n",ans);
	}

}

#include<iostream>

using namespace std;
int hashmm[101];
int arr[1000];
int main(){

    int test;
    cin >>  test;
    for (int t= 0 ; t< test; t++){
        int n,k,d;
        int minans,tempmin,len;
        cin >> n>>  k>>d;
        len=0;
        minans=8888;
        tempmin=0;
        for(int i =0 ; i<=k;i++){
            hashmm[i]=0;
        }

        for (int i= 0 ; i<n ; i++){
            cin>>arr[i];
            if(len<d){
                if(hashmm[arr[i]]==0){
                    tempmin++;
                }
                hashmm[arr[i]]++;
                len++;
            }else {
                minans= (minans<tempmin)?minans:tempmin;
                if(hashmm[arr[i]]==0){
                    tempmin++;
                }
                hashmm[arr[i]]++;
                hashmm[arr[i-d]]--;
                if(hashmm[arr[i-d]] == 0 ){
                    tempmin--;

                }
            }
        }
        minans= (minans<tempmin)?minans:tempmin;
        cout << minans <<endl;
    }

    return 0;
}

#include <bits/stdc++.h>

#define ll long long
#define pii pair<int, int>

using namespace std;

int main() {
    int t;
    cin >> t;
    while (t--) {
        int n, k, d;
        cin >> n >> k >> d;
        vector<int> a(n);
        for (int i = 0; i < n; i++)cin >> a[i];
        map<int, int> mp;
        for (int i = 0; i < d; i++)mp[a[i]]++;
        int ans = mp.size();
        int cur = ans;
        for (int i = d; i < n; i++) {
            mp[a[i - d]]--;
            mp[a[i]]++;
            if (mp[a[i - d]] == 0)
                mp.erase(a[i - d]);
            ans = min(ans, (int)mp.size());
        }
        cout << ans << endl;
    }
}

#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
using namespace std;
int main(void){
    int t;
    scanf("%d", &t);
    while(t --){
        //现在我们要计算长度为d中出现数字最小的子序列
        int n, k, d;
        scanf("%d%d%d", &n, &k, &d);
        vector<int> arr(n);
        for(int i = 0; i < n; i ++){
            scanf("%d", &arr[i]);
        }
        int cnt = 0;
        map<int, int> mem;
        for(int _ = 0; _ < d; _ ++){
            if(mem[arr[_]] == 0){
                cnt ++;
            }
            mem[arr[_]] ++;
        }
        int minn = cnt;
        for(int i = 1, j = d; j < n; i ++, j ++){
            if(arr[i - 1] == arr[j]) continue;
            if(mem[arr[j]] == 0){
                cnt ++;
            }
            if(mem[arr[i - 1]] == 1){
                cnt --;
            }
            mem[arr[i - 1]] --;
            mem[arr[j]] ++;
            minn = min(minn, cnt);
        }
        printf("%d\n", minn);
    }
    return 0;
}

#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;

const int N = 1000010;
const int INF = 0x3f3f3f3f;

int a[N], num[N], t;
int n, k, d;

int main()
{
	scanf("%d", &t);
	while (t--) {
        memset(num, 0, sizeof(num));
		scanf("%d%d%d", &n, &k, &d);
		int cnt = 0, res = INF;
		for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
		for (int i = 1; i <= d; i++) {
			if (!num[a[i]]) cnt++;
			num[a[i]]++;
		}
		res = min(res, cnt);
		// cout << res << endl;
		for (int i = 1; i <= n - d; i++) {
			if (!num[a[i + d]]) cnt++;
			num[a[i + d]]++;
			num[a[i]]--;
			if (!num[a[i]]) cnt--;
			// cout << res << endl;
			res = min(res, cnt);
		}
		printf("%d\n", res);
		//for (int i = n - d + 1; i <= n; i++) num[a[i]] = 0;
	}
	return 0;
}

//#include "stdafx.h"
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <cmath>

long long t;
long long input[1000002];
long long data[1000002];
long long last = 0;
std::vector<long long> ans;
int main()
{
	for (int i = 0; i < 1000001; i++)
	{
		input[i] = 0;
	}
	std::cin >> t;
	for (int y = 0; y < t; y++)
	{
		long long n, k, d;
		long long min;
		std::cin >> n >> k >> d;
		for (int i = 0; i < last; i++)
			data[i] = 0;
		last = k + 1;
		for (int i = 0; i < n; i++)
			std::cin >> input[i];
		long long a = 0;
		for (int i = 0; i < d; i++)
		{
			if (data[input[i]] == 0)
				a++;
			data[input[i]]++;
		}
		min = a;
		for (int i = d; i < n; i++)
		{
			if (data[input[i - d]] == 1)
			{
				a--;
			}
			data[input[i - d]]--;
			if (data[input[i]] == 0)
			{
				a++;
			}
			data[input[i]]++;
			min = std::min(min, a);

		}
		ans.push_back(min);

	}
	for (long long i : ans)
		std::cout << i << '\n';
}

#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <string>
#include <cctype>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <list>
#include <set>
#include <map>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int N = 1e6 + 10;
const int INF = 0x3f3f3f3f;
const double eps = 1e-10;
const double PI = 2 * acos(0.0);
int a[N], cnt[N];
int main() {
	//freopen("out.txt", "w+", stdout);
	//You say, so food, you still so lazy, play a fart
	//ios::sync_with_stdio(false);
	//cin.tie(0); cout.tie(0);

	int t, n, k, d; scanf("%d", &t);
	while (t--) {
		memset(cnt, 0, sizeof(cnt));
		scanf("%d%d%d", &n, &k, &d);
		for (int i = 0; i < n; i++) scanf("%d", &a[i]);
		int min_num = INF << 1, num = 0;
		for (int i = 0; i < d; i++) {
			if (!cnt[a[i]]) num++; cnt[a[i]]++;
		}
		min_num = min(min_num, num);
		for (int i = d; i < n ; i++) {
			if (!cnt[a[i]]) num++;
			cnt[a[i]]++, cnt[a[i - d]]--;
			if (!cnt[a[i - d]]) num--;
			min_num = min(min_num, num);
		}
		printf("%d\n", min_num);
	}
	return 0;
}

#include <iostream>
#include <queue>
#include <vector>
#include <algorithm>
#include <numeric>
#include <string>
#include <cstring>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <set>
#include <map>
#include <numeric>
#include <cstdlib>
#include <climits>
#include <cmath>
#include <cstdio>
#define vi vector<int>
#define si set<int>
#define ll unsigned long long
//#define int long long

const int maxn = 2*10e5 + 10;
const int maxk = 10e6 + 10;

using namespace std;

int t, n, k, d;
int a[maxn];

int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cin >> t;
    while(t--){
    	cin >> n >> k >> d;

    	unordered_map<int, int> cnt;
    	for(int i = 0; i < n; i++){
    		cin >> a[i];
    	}
    	int ans = 0;
    	int mina = INT_MAX;
    	for(int i = 0; i < d; i++){
    		int s = a[i];
    		if(cnt[s] == 0) ans++;
    		cnt[s]++;
    	}
    	mina = min(mina, ans);
    	int ri = d;
    	while(ri < n){
    		int s = a[ri];
    		int le = ri - d;
    		if(cnt[s] == 0){
    			ans++;
    		}
    		cnt[s]++;

    		if(cnt[a[le]] == 1){
    			ans--;
    		}
    		cnt[a[le]]--;
    		mina = min(mina, ans);
    		ri++;
    	}
    	cout << mina << endl;
    }
	return 0;
}

#include <iostream>
#include <cstdio>
#include <cstring>
#include <map>

using namespace std;

const int N=2e5+10;

int a[N];

int main()
{
    int t,n,k,d;

    scanf("%d",&t);

    while(t--)
    {
        map<int,int> m;

        scanf("%d%d%d",&n,&k,&d);
        for(int i=0;i<n;i++)
            scanf("%d",&a[i]);

        int ans=0;
        for(int i=0;i<d;i++)
        {
            if(m[a[i]]==0)
                ans++;

            m[a[i]]++;
        }

        int cnt=ans;
        for(int i=0,j=d;j<n;i++,j++)
        {
            m[a[i]]--;
            if(m[a[i]]==0)
                cnt--;

            m[a[j]]++;
            if(m[a[j]]==1)
                cnt++;

            ans=min(ans,cnt);
        }

        printf("%d\n",ans);
    }

    return 0;
}

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define ll long long
using namespace std;
int n,k,d;
int a,la[1000001],vis[200010],ans=0x7f7f7f7f,sum;
int main(){
    int t;
    scanf("%d",&t);
    while(t--){
        memset(la,0,sizeof(la));
        memset(vis,0,sizeof(vis));
        ans=0x7f7f7f7f,sum=0;
        scanf("%d%d%d",&n,&k,&d);
        for(register int i=1;i<=n;i++){
            scanf("%d",&vis[i]);a=vis[i];
            if(la[a]<=i-d||la[a]==0){
                sum++;
            }
            if(la[vis[i-d-1]]<i-d)sum--;
            //if(ans>sum)cout<<i<<" "<<sum<<endl;
            if(i-d>=0)ans=min(ans,sum);
            la[a]=i;
        }
        printf("%d\n",ans);
    }
    return 0;
}

#include <iostream>
#include <cmath>
using namespace std;

main()
{
    int t ,n, d, k, mn = 1000000, p = 0;
    cin >> t;
    while (t--)
    {
    	cin >> n >> k >> d;
    	int a[n] , b[k+1];
    	for(int i = 0; i< k+1;i++) b[i] = 0;
    	for(int i = 0; i< n;i++) cin >> a[i];
		for(int i = 0; i < n - d +2; i++)
    	{
    		for(int j = i; j < i+d; j++) b[a[j]]++;
			for(int j = 0; j < k+1; j++) if(b[j] > 0) p++, b[j] = 0;
			mn = min(mn, p);
			p = 0;
		}
		cout << mn << endl;
		mn = 1000000;
	}
	return 0;
}

#include<iostream>
#include<cstring>
#include<string>
#include<bits//stdc++.h>
#include<algorithm>
#include<cmath>
using namespace std;
int different(int A[],int n){
int res = 1;

    for (int i = 1; i < n; i++) {
        int j = 0;
        for (j = 0; j < i; j++)
            if (A[i] == A[j])
                break;

        if (i == j)
            res++;
    }
    return res;
}
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,d;
		cin>>n>>k>>d;
		int A[n];
		int count,mincount=10000;
		for(int i=0;i<n;i++)
		{
			cin>>A[i];
		}

		for(int i=0;i<=n-d;i++)
		{
			int B[d]={0};
			for(int j=i;j<i+d;j++)
			{
				B[j-i]=A[j];
			}
			count=different(B,d);
			if(count==1) break;
			else
			{
				if(mincount>count) mincount=count;
			}
			//cout<<mincount<<endl;

		}
		cout<<mincount<<endl;

	}
}

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#define lld long long int
using namespace std;
#define rep(i,start,end) for(lld i = start;i<end;i++)
#define newline cout << endl
#define fastio ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
#define se second
#define fi first
const lld MOD=1e+9+7;

int main()
{
    lld t;
    cin >> t;
    while(t--)
    {
        lld n,k,d,a[200005];
        cin >> n >> k >> d;
        rep(i,1,n+1)
            cin >> a[i];

        lld f = 3000000;
          set<lld> s;
          set<lld>::iterator it;
         map<lld,lld> m;

        for(lld i = 1;i<=n;i++)
        {
           if(i<d)
             s.insert(a[i]);
             m[a[i]] = i;
             if(i>=d)
             {
                 s.insert((a[i]));
                  if(m[a[i-d]]<=i-d)
                    {
                        s.erase(a[i-d]);
                    }
                   f = f<s.size()?f:s.size();

            }

        }
      /*if(n==d)
            cout << s.size() << endl;
        else
        cout << f << endl; */
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t;
	cin>>t;
	while(t--)
	{
		int n,k,d;
		cin>>n>>k>>d;
		int ar[n];
		for(int i=0;i<n;++i)
		{
			cin>>ar[i];
		}
		int mp[k];
		memset(mp,0,sizeof(mp));

		int i;set<int>st;
		for(int i=0;i<d;++i)
		{
			mp[ar[i]]++;
			st.insert(ar[i]);
		}
		int m=st.size();
		for(int i=d;i<n;++i)
		{
			mp[ar[i-d]]--;
			mp[ar[i]]++;
			if(mp[ar[i-d]]==0)
			st.erase(st.find(ar[i-d]));
			st.insert(ar[i]);
			if(m>st.size())
			m=st.size();

		}
		cout<<m<<endl;
	}
}

#include <iostream>
using namespace std;

int countDistinct(int arr[], int n)
{
    int res = 1;

    // Pick all elements one by one
    for (int i = 1; i < n; i++) {
        int j = 0;
        for (j = 0; j < i; j++)
            if (arr[i] == arr[j])
                break;

        // If not printed earlier, then print it
        if (i == j)
            res++;
    }
    return res;
}

int main(){
    int t,n,k,d,i=0,j=0,l=0,ind=0;
    cin>>t;
    int a[t];
    for(i=0;i<t;i++)
    {
        cin>>n>>k>>d;
        int s[n],b=0,c=0,m=d,ds[d],p=0;
        for(j=0;j<n;j++)
        {
        cin>>s[j];
        }
        for(j=0;j<n-d;j++)
        {
            b=s[j];
            p=0;
            for(l=j;l<j+d;l++)
            {
                ds[p]=s[l];
                p++;
            /* if (b==s[l])
           { continue;}
            else
            {c++;} **/
            }
            c=countDistinct(ds,d);
           if(j==0)
           m=c;
           else{
            if(m>c)
            {m=c;}
           }
        }
    a[ind]=m;
    ind++;
}
for(i=0;i<t;i++)
{cout<<a[i]<<endl;}

return 0;

}

#include<bits/stdc++.h>
using namespace std;
int main()
{
//    ios::sync_with_stdio(0);
//    cin.tie(0);
//    cout.tie(0);
    int t;
    scanf("%d",&t);
    //cin >> t;
    while(t--)
    {
        int n, k, d;
        scanf("%d%d%d",&n,&k,&d);
       // cin >> n >> k >> d ;
        int ar[n+1] ;
        map<int,int>m;
        for( int i=0; i<n; i++)
        {
            cin >> ar[i];
        }
        int cnt = 0;
        for(int i=0;i<d;i++)
        {
            if(!m[ar[i]]) cnt++;
            m[ar[i]]++;
        }
        int ans = cnt;
        for(int l=0,hi=d;hi<n;l++,hi++)
        {
            if(ar[l]!=ar[hi])
            {
                m[ar[l]]--;
                m[ar[hi]]++;
                if(m[ar[hi]]==1) cnt++;
                if(m[ar[l]]==0) cnt--;
                ans = min(ans,cnt);
            }

        }
        printf("%d\n",ans);
        cout << ans << endl;
    }
   return 0;
}

#include<iostream>
#include<string>
#include<cstring>
#include<utility>
#include<map>
#include<queue>
#include<vector>
#include<set>
#include<cstdio>
#include<algorithm>
#include<functional>
using namespace std;

int z[1000005];
int a[200005];

int main() {
	int q;
	cin >> q;
	while (q--) {
		memset(z, 0, sizeof(z));
		int n, k, d;
		int sum=0;
		int minx = 1000005;
		cin >> n >> k >> d;
		for (int i = 0; i < n; i++) {
			scanf("%d", &a[i]);
		}
		for (int i = 0; i < d; i++) {
			if (!z[a[i]])sum++;
			z[a[i]]++;
		}
		minx = sum;
		for (int x = 0, y = d; y < n&&x < n; x++) {
			z[a[x]]++;
			if (!z[a[x]])sum--;
			if (y < n) {
				if (!z[a[y]])sum++;
				z[a[y]]++;
				y++;
			}

			minx = min(minx, sum);
		}
		cout << minx << endl;
	}
}

/*
  BY_KUTBILIM
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

#define endl '\n'
#define pb push_back
#define ff first
#define ss second

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const double eps = (double)1e-9;
const int inf = (int)1e9+7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--){
		int n, k, d;
		cin >> n >> k >> d;
		int cnt[k+1] = {0};
		int a[n], c = 0;
		int ans;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			cnt[a[i]]++;
			if(cnt[a[i]] == 1)c++;
			if(i == d - 1){
				ans = c;
			}
			else if(i >= d){
				cnt[a[i-d]]--;
				if(cnt[a[i-d]] == 0){
					c--;
				}
				ans = min(ans, c);
			}
			cout << i << " " << c << endl;
		}
		cout << ans << endl;
	}

	return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
   int t;
    cin>>t;
    while(t--)
    {
        int n,k,d;
        cin>>n>>k>>d;
        set<int> s;
        int ma=n;
        int a[n];
        map<int,int> m;
        for(int i=0;i<d;i++)
        {
            cin>>a[i];
            m[a[i]]++;
            s.insert(a[i]);
        }

        ma=min(ma,int(s.size()));
        for(int i=d;i<n;i++)
        {
            cin>>a[i];
            s.insert(a[i]);
            m[a[i]]++;
            if(m[a[i-d]]==0)
                  s.erase(s.find(a[i-d]));

            ma=min(ma,int(s.size()));
        }
        cout<<ma<<endl;
    }
}

#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

void solve() {
    int n, k, d;
    cin >> n >> k >> d;

    vector<int> arr(n);

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    map<int, int> m;
    int difs = 0;

    int ans = k;
    for (int i = 0; i < n; i++) {
        m[arr[i]]++;
        if (m[arr[i]] == 1) difs++;

        if (i - d >= 0) {
            m[arr[i - d]]--;
            if (m[arr[i - d]] == 0) difs--;
        }

        ans = min(difs, ans);
    }

    cout << difs << endl;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;
int dx[] = { -1, 1, 0, 0, -1, 1, -1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, 1, -1 };
const int oo = 2e9 + 5;
const int N = 1e6;

int t, n, k, d, a[N], f[N + 5];

void print() {
    for(int i = 1; i <= k; i++)
        cout << f[i] << " ";
    cout << endl;
}

int main() {
    io
    cin >> t;
    while(t--) {
        cin >> n >> k >> d;
        for(int i = 0; i < n; i++) {
            cin >> a[i];
            f[i] = 0;
        }
        int ans = oo, cnt = 0, l = 0;
        for(int i = 0; i < n; i++) {
            if(!f[a[i]]) cnt++;
            f[a[i]]++;
            if(i - l + 1 > d) {
                f[a[l]]--;
                if(!f[a[l++]]) cnt--;
            }
            if(i - l + 1 == d)
                ans = min(ans, cnt);
        }
        cout << ans << "\n";
    }
    return 0;
}

#define _CRT_SECURE_NO_DEPRECATE
#include <iostream>
#include <vector>
#include <algorithm>
#define LL long long
#define fori(i, start, end) for (int i = start; i < end; i++)
using namespace std;

int main(){
	int t;
	cin >> t;
	for (int i = 0; i < t; i++) {
		int n;
		int p;
		int d;
		cin >> n >> p >> d;
		int* shows = new int[n];
		for (int j = 0; j < n; j++) {
			cin >> shows[j];
		}
		int minCount = d;
		bool* alreadyWas = new bool[p];
		for (int j = 0; j < n - d + 1; j++) {
			fill_n(alreadyWas, p + 1, false);
			int count = 0;
			for (int k = 0; k < d; k++) {
				if (!*(alreadyWas + *(shows + j + k))) {
					*(alreadyWas + *(shows + j + k)) = true;
					count++;
				}
			}
			minCount = min(count, minCount);
		}
		cout << minCount;
	}
}

#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"

int pow1(int n, int p)
{
	if(p==0)	return 1;
	int x=pow1(n, p/2);
	x=(x*x)%mod;
	if(p%2==0)
		return x;
	else
		return (x*n)%mod;
}

int32_t main()
{
	fast;
	int t;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		int n, k, d;
		cin>>n>>k>>d;
		// if(d==1)
		// {
		// 	cout<<1<<endl;
		// 	continue;
		// }
		vector<int> v(n);
		for(int i=0;i<n;i++)
			cin>>v[i];
		if(d==1)
			continue;
		vector<int> v2(k+1, 0);
		set<int> s;
		int mn=k;
		for(int i=0;i<n;i++)
		{
			v2[v[i]]++;
			if(v2[v[i]]==1)
				s.insert(v[i]);
			if(i<d-1)
				continue;
			if(i>=d)
			{
				v2[v[i-d]]--;
				if(v2[v[i-d]]==0)
					s.erase(v[i-d]);
			}
			mn=min(mn, (int)s.size());
		}
		cout<<mn<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define N 200005

int a[N];
int b[1000005];

int main(){
    int t;
    cin>>t;
    int m = 10000000;
    while(t--){
        int n,k,d;
        cin>>n>>k>>d;
        memset(b,0,sizeof(b));

        for(int i=1;i<=n;i++){
            cin>>a[i];
        }
        int min=1;
        int count=0;
        for(int i=1;i<=d;i++){
             if(b[a[i]]){
                b[a[i]]++;

             }
             else{
                 count++;
                 b[a[i]]++;
             }

        }
        min=count;

        for(int i=d+1;i<=n;i++){
            b[a[i-d]]--;
            if(b[a[i-d]]==0){
                count--;
            }

             if(b[a[i]]){
                b[a[i]]++;

             }
             else{
                 count++;
                 b[a[i]]++;
             }
        }
       cout<<count<<endl;

    }
}

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n, k, d;
        cin >> n >> k >> d;
        vector<int> a(n);
        for (int i = 0; i < n; i++) {
            cin >> a[i];
        }

        vector<int> used(2000005, 0);
        int res = 0;
        for (int i = 0; i < d; i++) {
            if (!used[a[i]]) {
                res++;
            }
            used[a[i]]++;
        }

        int cur = res;
        for (int i = d; i < n; i++) {
            if (!used[a[i]]) {
               cur++;
            }
            used[a[i]]++;
            if (used[a[i - d]] == 1) {
                cur--;
            }

            res = min(res, cur);
        }

        cout << res << endl;

    }
}

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
int t, n, kk, d, a[200003], flag[1000003], minn;
int main(){
	cin>>t;
	for(int i = 1; i <= t; i ++){
		cin>>n>>kk>>d;
		minn = 0;
		for(int j = 1; j <= n; j ++){
			cin>>a[j];
		}
		for(int j = 1; j <= kk; j ++)
			flag[j] = 0;
		for(int j = 1; j <= d; j ++){
			if(!flag[a[j]]){
				flag[a[j]] ++;
				minn ++;
			}
		}
		int left = 1, right = 1 + d - 1, sum = minn;
		while(right <= n){
			if(flag[a[left]] == 1){
				flag[a[left]] = 0;
				sum --;
			}
			else flag[a[left]] --;
			if(!flag[a[right + 1]]){
				flag[a[right + 1]] ++;
				sum ++;
			}
			else flag[a[right + 1]] ++;
			left ++;
			right ++;
		}
		minn = min(minn, sum);
		cout<<minn<<endl;
	}
	return 0;
}

#include<bits/stdc++.h>
#define ios std::ios::sync_with_stdio(false)
#define sd(n) scanf("%d",&n)
#define sdd(n,m) scanf("%d%d",&n,&m)
#define sddd(n,m,k) scanf("%d%d%d",&n,&m,&k)
#define pd(n) printf("%d\n", (n))
#define pdd(n,m) printf("%d %d\n", n, m)
#define pld(n) printf("%lld\n", n)
#define pldd(n,m) printf("%lld %lld\n", n, m)
#define sld(n) scanf("%lld",&n)
#define sldd(n,m) scanf("%lld%lld",&n,&m)
#define slddd(n,m,k) scanf("%lld%lld%lld",&n,&m,&k)
#define sf(n) scanf("%lf",&n)
#define sff(n,m) scanf("%lf%lf",&n,&m)
#define sfff(n,m,k) scanf("%lf%lf%lf",&n,&m,&k)
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,n,a) for (int i=n;i>=a;i--)
#define mm(a,n) memset(a, n, sizeof(a))
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define ll long long
#define MOD 1000000007
#define pi 3.14159265358979323
#define lrt rt<<1
#define rrt rt<<1|1
#define lson l, m, lrt
#define rson m+1, r, rrt
#define debug(x) 			  cout << #x << ": " << x << endl
#define debug2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<< endl;
#define debug3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
using namespace std;
const ll INF (0x3f3f3f3f3f3f3f3fll);
const int inf (0x3f3f3f3f);
template<typename T>void read(T &res){bool flag=false;char ch;while(!isdigit(ch=getchar()))(ch=='-')&&(flag=true);
for(res=ch-48;isdigit(ch=getchar());res=(res<<1)+(res<<3)+ch - 48);flag&&(res=-res);}
template<typename T>void Out(T x){if(x<0)putchar('-'),x=-x;if(x>9)Out(x/10);putchar(x%10+'0');}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll pow_mod(ll x,ll n,ll mod){ll res=1;while(n){if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
ll fact_pow(ll n,ll p){ll res=0;while(n){n/=p;res+=n;}return res;}
ll mult(ll a,ll b,ll p){a%=p;b%=p;ll r=0,v=a;while(b){if(b&1){r+=v;if(r>p)r-=p;}v<<=1;if(v>p)v-=p;b>>=1;}return r;}
ll quick_pow(ll a,ll b,ll p){ll r=1,v=a%p;while(b){if(b&1)r=mult(r,v,p);v=mult(v,v,p);b>>=1;}return r;}
bool CH(ll a,ll n,ll x,ll t)
{ll r=quick_pow(a,x,n);ll z=r;for(ll i=1;i<=t;i++){r=mult(r,r,n);if(r==1&&z!=1&&z!=n-1)return true;z=r;}return r!=1;}
bool Miller_Rabin(ll n)
{if(n<2)return false;if(n==2)return true;if(!(n&1))return false;ll x=n-1,t=0;while(!(x&1)){x>>=1;t++;}srand(time(NULL));
ll o=8;for(ll i=0;i<o;i++){ll a=rand()%(n-1)+1;if(CH(a,n,x,t))return false;}return true;}
int prime[30000010],minprime[30000010];
void euler(int n)
{int c=0,i,j;for(i=2;i<=n;i++){if(!minprime[i])prime[++c]=i,minprime[i]=i;for(j=1;j<=c&&i*prime[j]<=n;j++)
{minprime[i*prime[j]]=prime[j];if(i%prime[j]==0)break;}}}

const int N = 2e5 + 10;
set<int>haha;
int a[N];
int main()
{
	ios;
	int t;
	cin >> t;
	while(t --)
	{
		haha.clear();
		int n , k , d;
		cin >> n >> k >> d;
		rep(i , 1 , n)
		cin >> a[i];
		int minn = inf;
		rep(i , 1 , d)
		{
			haha.insert(a[i]);
		}
		int len = haha.size();
		minn = min(len , minn);
		rep(i , 9 , n - 1)
		{

			haha.erase(a[i - 1]);
			haha.insert(a[i + 1]);
			len = haha.size();
			minn = min(len , minn);
		}
		cout << minn << '\n';

	}
}

#include<bits/stdc++.h>
using namespace std;

int main()
{
    int test;
    cin>>test;
    int pos,n,k,d,arr[1000005],arr2[1000005],temp;
    while(test--){
        cin>>n>>k>>d;
        temp = 100000000;
        int val = 0;
        memset(arr2,0,sizeof(arr2));
        for(int i = 0; i < n; i++){
            cin>>arr[i];
        }
        for(int i = 0; i < n; i++){
            if(i >= d){
                arr2[arr[i-d]]--;
                if(arr2[arr[i-d]] == 0){
                    val--;
                }
            }
            if(arr2[arr[i]] != 0){
                arr2[arr[i]]++;
            }
            else{
                arr2[arr[i]]++;
                val++;
            }
            if(i >= d){
            //    cout<<"manjur"<<" "<<val<<endl;
                temp = min(val,temp);
            }
            else if(i == n-1){
                temp = min(val,temp);
            }
        }
      //  cout<<"manjur "<<temp<<endl;
      cout<<temp<<endl;
    }
    return 0;
}

#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>
typedef long long ll;

using namespace std;

const int MAXN = 2e5 + 5;
int a[MAXN];

int main() {
	int q;
	cin >> q;
	while (q--) {
		int n, k, d;
		cin >> n >> k >> d;
		for (int i = 0; i < n; i++) {
			cin >> a[i];
			a[i]--;
		}
		int now = 0, ans = k;
		vector<int> used(k);
		for (int i = 0; i < d; i++) {
			if (!used[a[i]]) {
				now++;
				used[a[i]]++;
			}
		}
		ans = min(ans, now);
		//cout << now << "__\n";
		for (int i = 1; i < n - d; i++) {
			used[a[i]]--;
			used[a[i + d]]++;
			if (used[a[i]] == 0)
				now--;
			if (used[a[i + d]] == 1)
				now++;
			//cout << now << "__\n";
			ans = min(ans, now);
		}
		cout << ans << "\n";
	}
	return 0;
}

/*
ID: imran151
TASK: ride
LANG: C++
*/

#include<bits/stdc++.h>
using namespace std;

// - - - - - - Data Types - - - - - - //

typedef long int LI;
typedef long long LL;

// - - - - - - Vectors - - - - - - //
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<double> VD;
typedef vector<VI> VVI;

#define scanVI(v, n)        for(int i=0; i<n; i++){ int x; cin >> x; v.PB(x); }
#define scanVLLI(v, n)      for(int i=0; i<n; i++){ LLI x; cin >> x; v.PB(x); }
#define scanVS(v, n)        for(int i=0; i<n; i++){ string x; cin >> x; v.PB(x); }
#define scanVD(v, n)        for(int i=0; i<n; i++){ double x; cin >> x; v.PB(x); }

// - - - - - - Maps - - - - - - //
typedef map<int, int> MII;
typedef map<int, string> MIS;
typedef map<int, char> MIC;
typedef map<string, int> MSI;
typedef map<char, int> MCI;
typedef map<int, VI> MIVI;

// - - - - - - Pairs - - - - - - //
typedef pair<int, int> PII;
typedef pair<string, string> PSS;
typedef pair<char, char> PCC;
typedef pair<int, string> PIS;
typedef pair<int, char> PIC;
typedef pair<string, char> PSC;

// - - - - - - Sets - - - - - - //
typedef set<int> SI;
typedef set<LL> SLL;
typedef set<string> SS;
typedef set<char> SC;
// - - - - - - - - - - - - - - - - - - //

#define PF                  printf
#define SF                  scanf
#define PB                  push_back
#define POP                 pop_back()
#define PP                  prev_permutation
#define NP                  next_permutation
#define MP                  make_pair
#define CLRN(a, b)          memset(a, b, sizeof(a))
#define CLR(a)              memset(a, 0, sizeof(a))
#define ALL(a)              a.begin(), a.end()
#define ALLN(a, n)          (a, a+n)
#define BSRCN(a, n, x)      binary_search(ALLN(a, n), x)
#define BSRC                binary_search
#define MAX                 10000007
#define MIN                 -10000007
#define inf                 int(1e9+9)
#define PI                  acos(-1)
#define BR                  PF("\n")
#define FastIO              ios_base::sync_with_stdio(false)
#define READ()              freopen("input.txt", "r", stdin)
#define WRITE()             freopen("output.txt", "w", stdout)
#define len(a)              a.length()
#define rsort(a)            sort(a.rbegin(), a.rend())
#define pvec(v)             for(auto x: v) cout<<x<<" "

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - //
/*----------------------Graph Moves----------------*/
int ROW[]={+1,-1,+0,+0};
int COL[]={+0,+0,+1,-1};

int X[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
int Y[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move

int KX[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
int KY[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*------------------------------------------------*/

LL GCD(LL a, LL b) { return b == 0 ? a : GCD(b , a % b); }
int LCM(int a, int b) { return a * (b/GCD(a, b)); }
bool CMP(int a, int b) { return a>b; }

// - - - - - - - - - - - - - - - - - - - - - - - - - - - END - - - - - - - - - - - - - - - - - - - - - - - - - //

int main()
{
    // FastIO;
    #ifdef HOME
     clock_t Start=clock();
     freopen("in.txt", "r", stdin);
     freopen("out.txt", "w", stdout);
    #endif

    int t, poo=1;
    cin>>t;
    while (t--) {
        int n, k, d;
        cin>>n>>k>>d;
        int a[n+1], ans=inf, cnt=0;
        map<int, int> m;
        a[0]=0;
        for (int i=1; i<=n; i++) {
            cin>>a[i];
            // m[a[i]]=i;
            if (poo==23) {
                cout<<a[i]<<" ";
                continue;
            }
            if (i<d) {
                if (m[a[i]]<=0) {
                    cnt++;
                    m[a[i]]=i;
                }
                continue;
            }
            int p=i-d;
            if (m[a[p]]==p and p!=0)
                cnt--;
            if (m[a[i]]<=p)
                cnt++;
            m[a[i]]=i;
            ans=min(ans, cnt);
        }
        if (poo==23) {
            cout<<endl;
            goto END;
        }
        cout<<ans<<endl;
    }

    END:
    #ifdef HOME
     printf("\n>>Runtime: %.10fs\n", (double) (clock() - Start) / CLOCKS_PER_SEC);
    #endif
    return 0;
}

#include <string>
#include <fstream>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <list>
#include <iterator>

using namespace std;

int main()
{
	long long n, p;
	cin >> n >> p;
	long long now = n, temp, ans, i;
	long long cnt = 0;
	vector <long long> a(63);
	a[0] = 1;
	for (int i = 1; i < 63; i++)
		a[i] = 2 * a[i - 1];
	while (1)
	{
		temp = now;
		ans = 0;
		i = 62;
		while (temp > 0)
		{
			if (temp >= a[i])
			{
				temp = temp - a[i];
				ans++;
			}
			else
				i--;
		}
		if (ans <= cnt)
		{
			cout << cnt;
			return 0;
		}
		now -= p;
		if (now < 0)
		{
			cout << -1;
			return 0;
		}
		cnt++;
	}
}

/***

    Muhammad Imdad-Ul-Haque Rakib(Attari)
    CSE'19
    Chittagong,Bangladesh

***/

#include<bits/stdc++.h>

/**Definitions**/

#define               ek               first
#define               dui              second
#define               ld               long double
#define               ll               long long
#define               boost_           ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define               pb               push_back
#define               ppb              pop_back
#define               ull              unsigned long long
#define               over             return 0
#define               scan(i,n,a)      for(i=0;i<n;i++) cin>>a[i]
#define               MP               make_pair
#define               spc              " "
#define               Yes              cout<<"Yes"<<endl
#define               YES              cout<<"YES"<<endl
#define               yes              cout<<"yes"<<endl
#define               No               cout<<"No"<<endl
#define               NO               cout<<"NO"<<endl
#define               no               cout<<"no"<<endl
#define               loop(i,n)        for(i=0;i<n;++i)

using namespace std;

/** User-defined Functions **/

int gcd(int x,int y){
    if(x==0) return y;
    else return gcd(y%x,x);
}
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b){ return (a.second<b.second); }
bool sortbysecinrev(const pair<int,int>&a, const pair<int,int>&b){ return (a.second>b.second); }
bool sortbysize(string &s1,string &s2){ return s1.size() < s2.size(); }
bool sortinrev(const pair<int,int> &a, const pair<int,int> &b){ return (a.first > b.first); }

/** Main Function **/

int main(){

    boost_;

    int t;
    cin>>t;

    while(t--){
        int n,k,d;
        cin>>n>>k>>d;
        int a[n],mn,i,l;
        set<int>st;
        loop(i,n) {cin>>a[i]; st.insert(a[i]);}
        map<int,int>mp;
        mn=st.size();

        for(i=0;i<n;++i){
            ++mp[a[i]];
            if(i>=d){
                --mp[a[i-d]];
                if(!mp[a[i-d]]) mp.erase(a[i-d]);
                l=mp.size();
                mn=min(mn,l);
            }
        }
        cout<<mn<<endl;
    }

    over;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int t;
	cin>>t;
	while(t--)
	{
		set<int> s;
		int n,k,d,mini=999999,cnt=0;
		cin>>n>>k>>d;
		int a[n];
		for(int i=0;i<n;i++)
		{
			cin>>a[i];
		}
		for(int i=0;i<n-d+1;i++)
		{
			mini=999999;
			cnt=0;
			s.clear();
			for(int j=i;j<i+d;j++)
			{
				s.insert(a[j]);
			}
			for(auto j=s.begin();j!=s.end();j++)
			{
				cnt++;
			}
			mini=min(mini,cnt);
		}
		cout<<mini<<endl;
	}
}

#include <bits/stdc++.h>
using namespace std;
int cnt[2000009],ara[2000009];

int main(){

	// freopen("in.txt","r",stdin);

	int test;
	cin>>test;

	while(test--){

		int n,k,d;
		cin>>n>>k>>d;

		for(int i=0;i<n;i++){
			cin>>ara[i];
		}

		int td=d;

		int tot=0,mn=1000000009;
		for(int i=0,j=0;i<n && j<n;){

			if(td-->0){

				if(cnt[ara[j]]==0)
					tot++;

				cnt[ara[j]]++;
				j++;

			}
			else{

				if(cnt[ara[j]]==0)
					tot++;

				cnt[ara[j]]++;

				cnt[ara[i]]--;

				if(cnt[ara[i]]==0)
					tot--;

				i++;
				j++;

				mn=min(mn,tot);
			}

		}

		for(int i=0;i<n;i++){
			cnt[ara[i]]=0;
			ara[i]=0;
		}

		mn=min(mn,tot);

		if(d==1)
			cout<<1<<endl;
		else
			cout<<mn<<endl;

	}

}

#include<bits/stdc++.h>
using namespace std;
int main(){
int t;
cin>>t;
while(t--){
    int a,b,c;
    cin>>a>>b>>c;
    int p[a];
    set<int>s;
    for(int i=0;i<a;i++)
       cin>>p[i];
    reverse(p,p+a);
    for(int i=0;i<c;i++)
       s.insert(p[i]);
       cout<<s.size()<<endl;
}
}

//By Krishna Yadav
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define testcase(t) int t; cin>>t; while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef map<int, int> m32;
const int LIM = 2e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

int main(){
	map<int, int> m;
	int a[LIM];
	int t;
	cin>>t;
	while(t--){
		int n,k,d;
		cin>>n>>k>>d;
		m.clear();
		int ans=MOD, num=0;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			if(i<=d){
				m[a[i]]++;
				if(m[a[i]]==1) num++;
			}
			else{
				m[a[i]]++;
				m[a[i-d]]--;
				if(m[a[i]]==1) num++;
				if(m[a[i-d]]==0) num--;
			}
			if(i>=d) ans=min(num, ans);
		}
		cout<<ans<<endl;
	}
}

#include <bits/stdc++.h>

using namespace std;

int main() {
    int t, n, k, d, b, q, p;
    int x[110];
    multiset <int> c;
    cin>>t;
    for (int i=0;i<t;i++){
        cin>>n>>k>>d;
        q=0;
        for (int j=0;j<d;j++){
            cin>>b;
            x[j]=b;
            if (c.count(b)>=1){
                q++;
            }
            c.insert(b);
        }
        p=d-q;
        for (int j=d;j<n;j++){
            cin>>b;
            x[j]=b;
            c.erase(c.find(x[j-d]));
            c.insert(b);
            if (c.count(b)>=2){
                q++;
            }
            if (c.count(x[j-d])>=2){
                q--;
            }
            p=min(p,d-q);
        }
        cout<<p<<endl;
        c.clear();
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <set>
#include <map>

using namespace std;

void solve() {
    int n, k, d;
    cin >> n >> k >> d;

    vector<int> arr(n);

    for (int i = 0; i < n; i++) {
        cin >> arr[i];
    }

    map<int, int> m;
    int difs = 0;

    int ans = k;
    for (int i = 0; i < n; i++) {
        m[arr[i]]++;
        if (m[arr[i]] == 1) difs++;

        if (i - d >= 0) {
            m[arr[i - d]]--;
            if (m[arr[i - d]] == 0) difs--;
        }

        ans = min(difs, ans);
    }

    cout << difs << endl;
}

int main() {
    int t;
    cin >> t;
    for (int i = 0; i < t; i++) {
        solve();
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define pii pair<int,int>
#define fr first
#define sc second
#define rep(i,a,b) for(int i=a;i<b;i++)
// #define endl '\n'

const int MOD = 998244353;
const int N = 3e5 + 2;
int a[N];
void solve(){
	int n, k, d;
	cin >> n >> k >> d;
	rep(i, 0, n) cin >> a[i];
	int frq[N] = {0};
	int i = 0;
	int cnt = 0;
	while(i < d){
		frq[a[i]]++;
		if(frq[a[i]] == 1){
			cnt++;
		}
		i++;
	}
	int ans = cnt;
	for(i = d; i < n; i++){
		frq[a[i-d]]--;
		if(frq[a[i-d]] == 0) cnt--;
		frq[a[i]]++;
		if(frq[a[i]] == 1) cnt++;
		cout<<cnt<<" "<<ans<<endl;
		ans = min(ans, cnt);
	}
	cout<<ans<<"\n";
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	int t;
	cin>>t;
	// t = 1;
	while(t--){
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

#define ll              long long
#define pb              push_back
#define mp              make_pair
#define ff              first
#define ss              second
#define SQ(x)           ((x)*(x))
#define LCM(x,y)        (((x)/gcd((x),(y)))*(y))
#define PI              acos(-1)
#define SZ(x)           x.size() - 1
#define waa             printf("Ripon\n")
#define mem(a,b)        memset(a,b,sizeof(a))
#define rep(i,a,n)      for(int i=(int)(a);i<=(int)(n);i++)
#define per(i,n,a)      for(int i=(int)(n);i>=(int)(a);i--)
#define SC              scanf
#define PF              printf
#define all(v)          v.begin(), v.end()
#define allr(v)         v.rbegin(), v.rend()
#define sc(x)           scanf("%d",&x)
#define scl(x)          scanf("%lld",&x)
#define scc(x,y)        scanf("%d %d",&x,&y)
#define sccl(x,y)       scanf("%lld %lld",&x,&y)
#define sccc(x,y,z)     scanf("%d %d %d",&x,&y,&z)
#define scccl(x,y,z)    scanf("%lld %lld %lld",&x,&y,&z)
//Grid tour
int dx[] = { 0, 1, 0, -1, -1, 1, 1, -1 };
int dy[] = { 1, 0, -1, 0, -1, -1, 1, 1 };
int kx[] = { -2, -2, -1, 1, 2, 2, 1, -1 };
int ky[] = { -1, 1, 2, 2, 1, -1, -2, -2 };

int overlap(int rs,int re,int qs,int qe){ if(rs>qe or re<qs) return 0; else if(qs<=rs and re<=qe) return 1; else return 2;}

struct DATA {
    int zer=0,one=0;
};

#define mod 10000007
#define eps 1e-9
#define inf INT_MAX
#define mx 200009

int arr[mx];
int tree[mx*3];

set<int> build(int node, int st,int en){
    if(st>en){
        set<int > ss;
        return ss;
    }
    if(st==en){
        tree[node] = 1;
        set<int > s;
        s.insert(arr[st]);
        return s;
    }

    int left = 2*node;
    int right = left + 1;
    int mid = (st + en) / 2;

    set<int> ls = build(left,st,mid);
    set<int> rs = build(right,mid+1,en);

    for(auto it = ls.begin();it!=ls.end();it++){
        rs.insert(*it);
    }
    tree[node] = rs.size();
    return rs;

}

int query(int node,int st,int en,int lf,int rt){

    if(!overlap(st,en,lf,rt)){
        return INT_MIN;
    }else if(overlap(st,en,lf,rt)==1){
        return tree[node];
    }else{

        int left = 2*node;
        int right = left + 1;
        int mid = (st + en) / 2;

        return max(query(left,st,mid,lf,rt),query(right,mid+1,en,lf,rt));

    }
}

void solve(int T) {

    rep(i,0,mx*3) tree[i] = 0;

    int n,k,d;
    sccc(n,k,d);

    rep(i,1,n){
        sc(arr[i]);
    }

    build(1,1,n);

    int res = n;

    rep(i,1,n-d){
        res = query(1,1,n,i+1,i+d);
    }
    cout<<res<<'\n';

}

int main() {

    //freopen("file.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int T=1;
    sc(T);
    while(T--)  solve(T);
    return 0;
}

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef unsigned long long ull;

const int MOD = 1000000007 ; //  , 1000000009 , 1000000023 ,998244353
const ll INF = ll(1e18);
const ld PI = 4*atan((ld)1);

ll power(ll x,ll n) {
  ll result=1;
  while(n>0){
    if(n&1)result = ((result%MOD) * (x%MOD))%MOD;
    result %= MOD;
    x=((x%MOD)*(x%MOD))%MOD;
    x %= MOD;
    n >>= 1;
  }
  return result;
}
ll gcd(ll a,ll b){
  if(a==0)return b;
  return gcd(b%a,a);
}

int main() {
  #ifdef AVI
    freopen("input.txt" , "r" , stdin);
  #endif
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.precision(20);
  ll t;
  cin >> t;
  while(t--){
    ll n,k,d;
    cin >> n >> k >> d;
    vector<ll>ar(n+1);
    for(ll i=1 ; i<=n ; i++)cin >> ar[i];
    map<ll,ll>mp;
    set<ll>st;
    ll res = INF;
    if(d==n){
      cout << n << '\n';
      continue;
    }
    for(ll i=1 ; i<=n ; i++){
      mp[ar[i]]++;
      st.insert(ar[i]);
      if(i>=d+1)mp[ar[i-d]]--;
      if(!mp[ar[i-d]])st.erase(ar[i-d]);
      if(i>=d)res = min(res,ll(st.size()));
      //for(auto &x:st)cout << x << ' ';
      //cout << '\n';
    }

    cout << res << '\n';
  }
}

#include<bits/stdc++.h>
#define fastRead ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
using namespace std;
typedef int elemType;

int main(int argc,char **argv){
	fastRead;
	ll t,n,k,d;
	cin>>t;
	for (int i = 0; i < t; ++i)
	{
		cin>>n>>k>>d;
		elemType count=0,tmp=0;
		elemType *sequence=new int[n];
		elemType *show = new int[k];
		for (int j = 0; j < n; ++j){
			cin>>sequence[j];
		}
		for (int j = 0; j < d; ++j){
			show[sequence[j]-1]++;
		}
		for(int j=0;j<k;++j){
			if(show[j]!=0){
				tmp++;
			}
		}
		count=tmp;
		int j=d-1;
		while(++j<n){
			if(show[sequence[j]-1]++==0){
				tmp++;
			if(show[sequence[j-d+1]-1]--==1)
				tmp--;
			count=min(count,tmp);
			}
		}
		cout<<count<<'\n';
		delete[] sequence;
		delete[] show;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,d;
        cin>>n>>k>>d;
        int a[10000];
        for(int i=0;i<n;i++)
            cin>>a[i];
        set<int> s;
        int ans;
        for(int i=0;i<d;i++)
            s.insert(a[i]);
        ans=s.size();
        for(int i=1;i<n-d+1;i++)
        {
            s.erase(a[i]);
            s.insert(a[i+d-1]);
            ans=min(ans,int(s.size()));
        }
        cout<<ans<<endl;
    }
}

#include <iostream>
#include <cmath>
using namespace std;

main()
{
    int t ,n, d, k, mn = 1000000, p = 0;
    cin >> t;
    while (t--)
    {
    	cin >> n >> k >> d;
    	int a[n] , b[k+1];
    	for(int i = 0; i< k+1;i++) b[i] = 0;
    	for(int i = 0; i< n;i++) cin >> a[i];
		for(int i = 0; i < n - d +2; i++)
    	{
    		for(int j = i; j < i+d; j++) b[a[j]]++;
			for(int j = 0; j < k+1; j++) if(b[j] > 0) p++, b[j] = 0;
			mn = min(mn, p);
			p = 0;
		}
		cout << mn << endl;
		mn = 1000000;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int T, n, m, d;
int mark[222222], pro[222222];
int main()
{
	scanf("%d", &T);
	while(T--)
	{
		scanf("%d%d%d", &n, &m, &d);
		memset(pro, 0, sizeof(pro));
		memset(mark, 0, sizeof(mark));
		for(int i = 1; i <= n; i++) scanf("%d", &pro[i]);
		int lft = 0, rit = 0, len = 0, cnt = 0, ans = 0x7fffffff;
		while(lft <= rit && (rit <= n && lft <= n))
		{//cout<<"test::"<<lft<<' '<<rit<<' '<<len<<' '<<cnt<<endl;
			if(len < d)
			{
				len++;
				rit++;
				if(!mark[pro[rit]]) cnt++;
				mark[pro[rit]]++;
			}
			if(len >= d)
			{
				if(len == d) ans = min(ans, cnt);
				len--;
				mark[pro[lft]]--;
				if(!mark[pro[lft]]) cnt--;
				lft++;
			}
		}
		printf("%d\n", ans);
	}
	return 0;
}

#include <iostream>
#include <vector>;
#include <queue>
#include <math.h>
#include <set>

#define int long long

using namespace std;
const long long INF = 2e18;
vector<int> v;
set<int> ans;
int cnt_of_differnt = 0;
int mn = INF;

signed main()

{
    ios_base::sync_with_stdio(false);

    long long t = 0, n = 0, k = 0,d = 0;

    cin >> t;

    for(int i = 0; i < t;i++){
        cin >> n >> k >> d;
        v.clear();
        v.resize(n);
        ans.clear();
        for(int j = 0; j < n;j++)
            cin >> v[j];

        for(int p = 0; p < n; p += d){
            ans.clear();
            for(int h = 0; h < d;h++){
                ans.insert(v[p + h]);
            }
            long long sz = ans.size();
            mn = min(INF, sz);

        }
        if(ans.find(0) != ans.end())
            cout << mn - 1 << endl;
        else
            cout << mn << endl;

    }

    return 0;

}

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

void Evolution();

int main()
{
	int t;
	cin >> t;
	for (int i = 0; i < t; i++)
	{
		Evolution();
	}
	return 0;
}

void Evolution()
{
	int n, k, d;
	cin >> n >> k >> d;

	int a[200000];
	vector <int> s;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		if (find(s.begin(), s.end(), a[i]) == s.end())
		{
			s.push_back(a[i]);
		}
		a[i] = find(s.begin(), s.end(), a[i]) - s.begin();
	}

	int numb[200000] = {0}, l = 0;
	for (int i = 0; i < d; i++)
	{
		if (!numb[a[i]]) l++;
		numb[a[i]]++;
	}

	int lbest = l;
	for (int i = d; i < n; i++)
	{
		if (numb[a[i - d]] == 1) l--;
		numb[a[i - d]]--;
		if (!numb[a[i]]) l++;
		numb[a[i]]++;
		if (l < lbest) lbest = l;
	}
	cout << l << "\n";
}

#include <bits/stdc++.h>
using namespace std;
int main() {
int tc;
cin>>tc;
while (tc--) {
 int n,k,d;
 cin>>n>>k>>d;
 vector <int> v(n);
 for (int i=0;i<n;i++) cin>>v[i];
 int sol=k;
 for (int i=0;i<n;i++) {
    int cnt=d;
    int j=i;
    set <int> s;
    while (cnt-- && j<n) s.insert(v[j++]);
    if (cnt>0) break;
    sol=min(sol,int(s.size()));
 }
 cout<<sol<<endl;
}
return 0;
}

#include <bits/stdc++.h>
using namespace std;

template<typename T> istream &operator>>(istream &is, vector<T> &vec){ for (auto &v : vec) is >> v; return is; }
template<typename T> ostream &operator<<(ostream &os, const vector<T> &vec){ os << "["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const deque<T> &vec){ os << "deq["; for (auto v : vec) os << v << ", "; os << "]"; return os; }
template<typename T> ostream &operator<<(ostream &os, const set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_set<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T> ostream &operator<<(ostream &os, const unordered_multiset<T> &vec){ os << "{"; for (auto v : vec) os << v << ", "; os << "}"; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &pa){ os << "(" << pa.first << ", " << pa.second << ")"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename TK, typename TV> ostream &operator<<(ostream &os, const unordered_map<TK, TV> &mp){ os << "{"; for (auto v : mp) os << v.first << ": " << v.second << ", "; os << "}"; return os; }
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }
template<typename T> bool chmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool chmin(T &m, const T q) { if (q < m) {m = q; return true;} else return false; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2> &l, const pair<T1, T2> &r) { return make_pair(l.first - r.first, l.second - r.second); }
#define f first

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--) {
        int len, shows, target;
        cin >> len >> shows >> target;
        vector<int> arr(len);
        for(int i = 0; i < len; i++) {
            cin >> arr[i];
        }
        set<int> s;
        for(int i = 0; i < target; i++) s.insert(arr[i]);
        int small = s.size();
        for(int i = 1; i < len - target; i++) {
            s.erase(arr[i - 1]);
            s.insert(arr[i + target - 1]);
            if(s.size() < small) small = s.size();
        }
        cout << s.size() << endl;
    }
}

#include <vector>
#include<iostream>
#include <set>
using namespace std;
int main(){
	int t;
	cin >> t;
	while (t){
		int n, k, d;
		cin >> n >> k >> d;
		vector <int> a(n);
		for (int i = 0; i < n; ++i){ cin >> a[i]; }
		int c = 0;

		for (int i = 0; i < n - d + 1; ++i){
			set <int> s;
			for (int j = 0; j < d; ++j){
				s.insert(a[i + j]);
			}
			if (c == 0 || (s.size() < c)){ c = s.size(); }
		}
		cout << c;
		t--;
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define endll '\n'
#define C getchar()
using ll=long long;
#define pi acos(-1.0)
#define INF 0x3f3f3f3f
#define mod 1000000007
#define pii pair<int,int>
const int MAXN = 1e6 + 10;
#define stop system("pause")
#define lowbit(x) ((x) & (-x))
#define Temp template <typename T>
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, a, b) for (int i = a; i <= b; i++)
Temp inline void rd(T &s)
{
    s = 0;T t = 1, k = C;
    for (; k < '0' || k > '9'; k = C)if (k == '-') t = -1;
    for (; k >= '0' && k <= '9'; k = C) s = (s << 1) + (s << 3) + (k ^ 48);
    s *= t;
}

int n,k,d;
int a[MAXN];
int tag[MAXN];
int main()
{
	int t;rd(t);
	while(t--)
	{
		rd(n),rd(k),rd(d);
		for(int i=1;i<=n;++i) rd(a[i]);
		mem(tag,0);
		int sum=0;
		for(int i=1;i<=d;++i)
		{
			if(tag[a[i]]==0) ++sum;
			++tag[a[i]];
		}
		int ans=sum;
		int pre=sum;
		for(int l=2;l+d-1<=n;++l)
		{
			int r=l+d-1;
			sum=pre;
			--tag[a[l-1]];
			if(tag[a[l-1]]==0) --sum;
			if(tag[a[r]]==0) ++sum;
			ans=min(ans,sum);
			pre=sum;
		}
		printf("%d\n",ans);
	}
	//stop;
	return 0;
}

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m,k;
int a[200010];
int cnt[1000010];
int res,r;
int tac;
int Main()
{
	scanf("%d%d%d",&n,&m,&k);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	fill(cnt+1,cnt+1+m,0);
	for (int i=0;i<k;i++) cnt[a[i]]++;
	r=0;
	for (int i=1;i<=m;i++) r+=(cnt[i]>0);
	res=r;
	for (int i=k;i<n;i++)
	{
		cnt[a[i-k]]--;
		if (!cnt[a[i-k]]) r--;
		cnt[a[i]]++;
		if (cnt[a[i]]==1) r++;
		res=min(res,r);
	}
	printf("%d/n",res);
	return 0;
}
int main()
{
	scanf("%d",&tac);
	while (tac--) Main();
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int arr[200005];
int counter[200005];

int main() {
	ios_base::sync_with_stdio(false);

	int test, n, m, d;
	cin>>test;
	for(int i=0; i<test; ++i) {
		memset(counter, 0, sizeof(counter));
		cin>>n>>m>>d;
		for(int j=0; j<n; ++j) {
			cin>>arr[j];
		}
		if(d==1) {
			cout<<"1"<<endl;
		}
		else {
			int mn = 0, ans = 0;
			for(int j=0; j<d; ++j) {
				if(counter[arr[j]]==0) {
					++mn;
					++counter[arr[j]];
				}
			}
			ans = mn;
			for(int j=0, k=d; k<n; ++k, ++j) {
				++counter[arr[k]];
				if(counter[arr[k]]==1) {
					++mn;
				}
				--counter[arr[j]];
				if(counter[arr[j]]==0) {
					--mn;
					ans = min(mn, ans);
				}
			}

			cout<<ans<<endl;
		}
	}
	return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define bug(x) cerr<<#x<<'='<<x<<' '
#define debug(x) cerr<<#x<<'='<<x<<'\n'
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Ror(i,a,b) for(int i=b;i>=a;--i)
typedef long long ll;

const int M=1e6+5;

int cnt[M],n,A[M],kd,limt;

int num,T;

bool chk(int R,int stp){
	return R<n&&(num<stp||cnt[A[R+1]]!=0);
}
void Insert(int p){
	int x=A[p];
	if(cnt[x]==0)num++;
	cnt[x]++;
}
void Del(int p){
	int x=A[p];
	cnt[x]--;
	if(cnt[x]==0)num--;
}

bool check(int stp){
	num=0;
	For(i,1,n)cnt[A[i]]=0;
	int L=1,R=0;
	Insert(++R);
	while(L<=R){
		while(chk(R,stp))Insert(++R);
		if(R-L+1>=limt)return 1;
		Del(L++);
	}
	return 0;
}

void solve(){

	scanf("%d",&n);
	scanf("%d",&kd);
	scanf("%d",&limt);
	For(i,1,n)scanf("%d",&A[i]);
	int l=1,r=n,res=n;
	while(l<=r){
		int mid=(l+r)>>1;
		if(check(mid))res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%d\n",res);
}

int main(){
//	freopen("in.txt","r",stdin);
	scanf("%d",&T);
	while(T--)solve();

	return 0;
}

#include <iostream>

using namespace std;

int main() {
	int t;
	cin >> t;
	while (t--) {
		int n, k, d;
		cin >> n >> k >> d;
		int a[n];
		for (int i = 0; i < n; ++i)
			cin >> a[i];

		int freq[k] = {0};
		int x = 1;
		for (int i = 0; i < d; ++i) {
			if (freq[a[i]] == 0)
				++x;

			++freq[a[i]];
		}

		int mn = x;

		for (int i = 0; i < n - d; ++i) {
			--freq[a[i]];
			++freq[a[i + d]];

			if (freq[a[i]] == 0)
				--x;
			if (freq[a[i + d]] == 1)
				++x;

			if (x < mn)
				mn = x;
		}

		cout << mn << endl;
	}
}

#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<limits.h>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<complex>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF = 9223372036854775807;
const ll NINF=-100000000000000000;
const ll mod = 998244353;
ll power(ll x,ll y)
{
  if (y == 0)
    return 1;
  ll p = power(x, y/2) % mod;
  p = (p * p) % mod;

  return (y%2 == 0)? p : (x * p) % mod;
}
ll divide(ll a,ll b)
{
  if (a%b==0)
    {
      return a/b;
    }
  else
    return a/b +1;
}
ll gcd(ll a,ll b)
{
  if(b==0)
    return a;
  return gcd(b,a%b);
}
void test()
{
  ll n,k,d;
  cin>>n>>k>>d;
  vll a(n);
  for(int i=0;i<n;i++)
    {
      cin>>a[i];
    }
  multiset<ll>ss;
  set<ll>s;
  for(int i=0;i<d;i++)
    {
      s.insert(a[i]);
      ss.insert(a[i]);
    }
  ll m=s.size();
  for(int i=1;i<k-d;i++)
    {
      ss.erase(a[i-1]);
      if(ss.find(a[i-1])==ss.end())
	{
	  s.erase(a[i-1]);
	}
      ss.insert(a[i+d-1]);
      s.insert(a[i+d-1]);
      m=min(m,(ll)s.size());
    }
      cout<<m<<endl;

}
int main()
{
  int t;
  cin>>t;
  while(t--)
    {
      test();
    }
}

#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7FFFFFFF;
#define bug puts("here\n")
typedef long long ll;
void work()
{
    int n, k, d;
    cin >> n >> k >> d;
    int mis = 9999999;
    map<int, int> s;
    vector<int> v;
    int tmp;
    for (int i = 0; i < n; i++)
    {
        cin >> tmp;
        v.push_back(tmp);
    }
    int fr = 0;
    int back = d - 1;
    int cnt = 0;
    for (int i = 0; i < d; i++)
    {
        if (s.count(v[i]) == 0)
        {
            cnt++;
            s[v[i]] = 1;
        }
        else
            s[v[i]]++;
    }
    mis = min(mis, cnt);
    while (back < n)
    {
        if (s[v[fr]] == 1)
            cnt--;
        s[v[fr]]--;
        fr++;
        back++;
        if (s[v[back]] == 0)
            cnt++;
        s[v[back]]++;
        mis = min(mis, cnt);
    }
    cout << mis << endl;
}
int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("in.txt", "r", stdin);
    int t = 1;
    cin >> t;
    while (t--)
    {
        work();
    }
    return 0;
}

//#include <boost/multiprecision/cpp_int.hpp>
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define pi pair<ll,ll>
#define pb push_back
#define mp make_pair
#define in insert
#define F first
#define S second
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define test    ll T=0;cin>>T;while(T--)
#define fast    ios_base::sync_with_stdio(false);cin.tie(NULL)
//using namespace boost::multiprecision;
using namespace std;

int main(void) {
	fast;
	test{
	    ll n,k,d,ans,f=0;
	    cin>>n>>k>>d;
	    ll a[n],b[k+5];
	    memset(b,0,sizeof(b));
	    rep(i,0,n)
	    cin>>a[i];
	    rep(i,0,d){
	        if(!b[a[i]])
	        f++;
	        b[a[i]]++;
	    }
	    ans=d;
	    rep(i,1,n-d+1){
	        b[a[i-1]]--;
	        if(!b[a[i-1]])
	        f--;
	        if(!b[a[i+d-1]])
	        f++;
	        b[a[i+d-1]]++;
	        ans=min(ans,f);
	    }
	    cout<<ans<<"\n";
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
void solve(){
	int n, k, d, a[n+1],ans=9999;cin>>n>>k>>d;for(int i=0;i<n;i++) cin>>a[i];
	for(int i=0;i<=n-d;i++)
	{
		int cnt=0;vector<bool>v(101);
		for(int j=i;j<i+d;j++)if(!v[a[j]])cnt++, v[a[j]]=true;
		ans=min(ans,cnt);
	}
	cout<<ans;
}
int main(){int t;cin >> t;while(t--)solve();}

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
const int inf=1e9+7;
const int maxn=1e6+5;
using namespace std;

int ma[maxn];
int main()
{
    int  t ;
    scanf("%d",&t);
    int n,k,d;
    while(t--)
    {
        map<int,int>mp;
        scanf("%d%d%d",&n,&k,&d);
        for(int i=1;i<=n;i++){
            scanf("%d",&ma[i]);
        }
        if(d==1){
            cout<<1<<endl;continue;
        }
        int ant=0;
        for(int i=1;i<=d;i++){
            if(mp[ma[i]]==0){
                ant++;
            }
            mp[ma[i]]++;
        }
        for(int i=d+1;i<=n;i++)
        {
            int t=ant;
            if(mp[ma[i-d]]>1){
                mp[ma[i-d]]--;
                if(mp[ma[i]]==0){
                    t++;
                }
                mp[ma[i]]++;
            }
            else{
                mp[ma[i-d]]=0;
                t--;
                if(mp[ma[i]]==0){
                    t++;
                }
                mp[ma[i]]++;
            }
            ant=min(ant,t);
        }
        printf("%d\n",ant);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main()
{

   int t;
   cin>>t;
   ll n,k,d;
   while(t--)
   {
       cin>>n>>k>>d;
       int a[n];
       ll mn=INT_MAX;
       set<int>s;
       int cnt=0;
       map<int,int>m;
       int chk=1;
       for(int i=0;i<n;i++)
       {
           cin>>a[i];
          // m[a[i]]++;
           if(cnt<d) s.insert(a[i]),cnt++,m[a[i]]++;
           else
           {

               cnt++;
               if(m[a[i-d]]<2) s.erase(a[i-d]);
               else m[a[i-d]]--;
               s.insert(a[i]);
               m[a[i]]++;
               ll temp=s.size();
               mn=min(mn,temp);
           }
           if(cnt==d&&chk)
           {
               chk=0;
               ll temp=s.size();
               mn=min(mn,temp);
           }
       }
       cout<<mn<<endl;
   }
}

#include<bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("E:/Competitive Programming/input.txt", "r", stdin);
	freopen("E:/Competitive Programming/output.txt", "w", stdout);
#endif

	int t;
	cin >> t;
	int a[200002], distinct[200002];
	distinct[0] = 1;
	while (t--) {
		int n, k, d;
		cin >> n >> k >> d;
		for (int i = 0 ; i < n ; i++) cin >> a[i];
		unordered_set<int> maps;
		maps.insert(a[0]);
		for (int i = 1 ; i < n ; i++) {
			distinct[i] = 0;
			if (maps.find(a[i]) == maps.end()) {
				maps.insert(a[i]);
				distinct[i] = distinct[i - 1] + 1;
			} else {
				distinct[i] = distinct[i - 1];
			}
		}
		// for (int i = 0 ; i < n ; i++) cout << distinct[i] << " ";
		// cout << endl;

		int res = distinct[d - 1];
		int end = d - 1;
		for (int i = d ; i < n ; i++) {
			int val = distinct[i] - distinct[i - d];
			if (res > val and val != 0) {
				res = val;
				end = i;
			}
		}

		// cout << "END " << end << endl;

		unordered_set<int> ans;
		for (int i = end - d + 1; i <= end; i++) {
			ans.insert(a[i]);
		}

		cout << ans.size() << endl;
	}

	return 0;

}
/*
# stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
	* DON'T GET STUCK ON ONE APPROACH
*/

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll fun(ll l,ll h,ll arr[])
{
ll hash[100]={0};
ll count = 0;
    for(ll i=l;i<=h;++i)
       {
           if(hash[arr[i]] == 0)
           {
               ++count ;
               hash[arr[i]] = 1;
           }
       }
return count;
}
int main()
{
   ll t;
   cin>>t;
   while(t--)
   {
       ll n,k,d;
       cin>>n>>k>>d;
       if(d == 1)
       {
           cout<<"1\n";
       }
       else
       {
       ll arr[n];
       for(ll i=0;i<n;++i)
       cin>>arr[i];
       ll i = 0,j = d-1;
       ll ans = d;
       while(j < n)
       {
          ans = min(ans, fun(i,j,arr) );
          ++j;
          ++i;
       }
       cout<<ans<<"\n";
       }
   }
}

#include<bits/stdc++.h>
using namespace std;
long long n,t,m,k,d;
long long a[1000001],b[1000001];
int main()
{
	scanf("%lld",&t);
	while(t--)
	{
		scanf("%lld %lld %lld",&n,&k,&d);
		//memset(a,0,sizeof(a));
		//memset(b,0,sizeof(b));
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&a[i]);
			b[i]=0;
		}
		int min1=k;
		int l=1,r=d,s=0;
		for(int i=1;i<=d;i++)
		{
			if(b[a[i]]==0)
			{
				s++;
			}
			b[a[i]]++;
		}
		min1=s;
		for(int i=1;i<=n-d;i++)
		{
			b[a[i]]--;
			if(b[a[i]]==0)
			{
				s--;
			}
			if(b[a[i+d]]==0)
			{
				s++;
			}
			b[a[i+d]]++;
			min1=min(min1,s);
		}
		printf("%d\n",min1);
	}
}

//hey Stalker
#include<bits/stdc++.h>
#define ll long long
#define vect vector<ll>
#define pb push_back
#define f(n) for(i=0;i<n;i++)
#define F(n) for(i=1;i<=n;i++)
#define s second
#define mod 1000000007
#define Map map<ll , ll >
using namespace std;
main()
{ll t;
cin>>t;
while(t--)
{
	ll n,k,d;
	cin>>n>>k>>d;
	ll i;
	Map m;
	ll a[n];
	f(n)
		cin>>a[i];
	f(d)
			m[a[i]]+=1;
	ll ans=m.size();
	cout<<ans<<endl;
	for(i=d;i<n;i++)
	{
//		if(m.find(a[i])==m.end())
			m[a[i]]+=1;
		m[a[i-d]]--;
		if(m[a[i-d]]==0)
			m.erase(a[i-d]);
		ans=min(ans,(ll)m.size());

	}
	cout<<ans<<endl;
}
}

//By Krishna Yadav
#pragma GCC optimize ("-O2")
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define testcase(t) int t; cin>>t; while(t--)
#define forstl(i,v) for(auto &i: v)
#define forn(i,e) for(int i = 0; i < e; i++)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<ln
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef map<int, int> m32;
const int LIM = 2e5+5, MOD = 1e9+7;
int t,n,m,k,x,y;

int main(){
	map<int, int> m;
	int a[LIM];
	int t;
	cin>>t;
	while(t--){
		int n,k,d;
		cin>>n>>k>>d;
		m.clear();
		int ans=MOD, num=0;
		forn(i, n+1){
			cin>>a[i];
			if(i<=d){
				m[a[i]]++;
				if(m[a[i]]==1) num++;
			}
			else{
				m[a[i]]++;
				m[a[i-d]]--;
				if(m[a[i]]==1) num++;
				if(m[a[i]]==0) num--;
			}
			if(i>=d) ans=min(num, ans);
		}
		cout<<ans<<endl;
	}
}

#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<cstdlib>
using namespace std;
#define il inline
#define re register
#define debug printf("Now is Line : %d\n",__LINE__)
#define file(a) freopen(#a".in","r",stdin);freopen(#a".out","w",stdout)
//#define int long long
#define D double
#define inf 123456789
#define mod 1000000007
il int read() {
    re int x = 0, f = 1; re char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar();}
    while(c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
    return x * f;
}
#define rep(i, s, t) for(re int i = s; i <= t; ++ i)
#define drep(i, s, t) for(re int i = t; i >= s; -- i)
#define Next(i, u) for(re int i = head[u]; i; i = e[i].next)
#define mem(k, p) memset(k, p, sizeof(k))
#define lb(x) (x)&(-(x))
#define ls k * 2
#define rs k * 2 + 1
#define maxn 1000005
int n, m, k, d, a[maxn], ton[maxn], ans, Ans;
il void add(int a) {
	if(++ ton[a] == 1) ++ ans;
}
il void del(int a) {
	if(-- ton[a] == 0) -- ans;
}
int main() {
	int T = read();
	while(T --) {
		n = read(), k = read(), d = read(), ans = 0, Ans = inf;
		rep(i, 1, n) a[i] = read();
		rep(i, 1, d - 1) add(a[i]);
		rep(i, d, n) add(a[i]), Ans = min(ans, Ans), del(a[i - d]);
		printf("%d\n", Ans);
		rep(i, n - d, n) del(a[i]);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
set<int> p;

void f(ll n){
    int i=0;
    while (n){

        ll q=n%2;
        if(q){
           p.insert(i);
        }
        n/=2;
        i++;
    }
}
int main()
{
   ios::sync_with_stdio(0);
   cin.tie(0);cout.tie(0);
   ll q;
   cin>>q;
   for (int _=0;_<q;_++){
        int n,k,d;
        cin>>n>>k>>d;
        ll arr[n];
        for(int i=0;i<n;i++)cin>>arr[i];
        set<ll> s;
        map<ll,ll> m;
        for(int i=0;i<d;i++){
            s.insert(arr[i]);
            m[arr[i]]++;
        }
        ll ans=s.size();
        for(int i=d;i<n;i++){
            if(arr[i]!=arr[i-d]){
                m[arr[i-d]]--;
                if(!m[arr[i-d]]){
                    s.erase(arr[i-d]);
                }
                s.insert(arr[i+1]);
            }

            ans = min(ans,(ll)s.size());
            if(ans==1)break;
        }
        cout<<ans<<'\n';

   }

    return 0;
}

# define _CRT_SECURE_NO_WARNINGS
#include<functional>
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <stdio.h>
#include<iterator>
using namespace std;
typedef long long ll;
const double pi = acos(-1);
int t;
int main() {
	scanf("%d",&t);
	while(t--){
		int n,k,d;
		scanf("%d %d %d",&n,&k,&d);
		vector<int>v(n);
		for(int i=0;i<n;i++)
		scanf("%d",&v[i]);
		int mn=1e9;
		for(int i=0;i<n;i++){
			int ans=0;
			map<int,int>mp;
			for(int j=i;j<d+i;j++){
				mp[v[j]]++;
				if(mp[v[j]]==1)
				ans++;
			}
			mn=min(mn,ans);
		}
		printf("%d\n",mn);
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
int a[200005];
int main() {
	int t;
	cin>>t;
	while(t--)
	{
		memset(a,0,sizeof(a));
		int n,k,d;
		cin>>n>>k>>d;
		int arr[n];
		set<int> st;
		int minn=INT_MAX;
		int cnt=0;
		queue<int> q;
		for(int i=0;i<n;i++)
			cin>>arr[i];
		for(int i=0;i<n;i++)
		{
			if(cnt!=d)
			{
				cnt++;
				q.push(arr[i]);
				st.insert(arr[i]);
				a[arr[i]]++;
			}
			if(cnt==d)
			{
				int x=st.size();
				minn=min(minn,x);
				cnt--;
				int r=q.front();
				q.pop();
				if(a[r]==1)
				{
					st.erase(r);
				}
				else
				{
					a[r]--;
				}
			}
		}
		cout<<minn<<endl;
	}
	// your code goes here
	return 0;
}

#include <bits/stdc++.h>
using namespace std;

int t, ep , day , sub , x , ido , lj;
int db = 0;
int l = 0;
vector<int>v,block;
int main() {
cin >> t;
ido = 0;
for (int i=0;i<t;++i)
{
    cin >> ep >> sub >> day ;
    for (int c = 0; c<ep; c++) {
            cin >> x;
            v.push_back(x);
    for (int p=1;p<=ep;++p)
    {
        ido = ido +1;
        if (v[p]!=v[p-1])
        {
            db += 1;
        }
        if (ido == day)
        {
            ido =0;
            block.push_back(db);
            db=0;
            l += 1;
            p=l;
        }
    }
    for (int y =0;y<block.size();++y)
    {
        lj =max(lj,block[y]);
    }

cout << lj;

}
}
return 0;
}

#include<bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;
int32_t main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int t;
	cin >> t;
	while(t--)
	{
		int n,k,d;
		cin >> n >> k >> d;
		int a[n];
		for(int i = 0; i < n; i++)
		cin >> a[i];
		int mn = 1e15;
		for(int i = 0; i < n; i++)
		{
			set <int> s;
			if(i+d > n) break;
			for(int j = i; j < i+d; j++)
			s.insert(a[j]);
			int foo = s.size();
			cout << foo << "\n";
			mn = min(mn,foo);
		}
		cout << mn << "\n";
	}
	return 0;
}

#include <bits/stdc++.h>

using namespace std;

int main()
{
   int a;

   cin>>a;

   while(a--)
   {
       int b,c,d;

       cin>>b>>c>>d;

       int arr[b];

       map<int,int>cont;

       for(int j=0;j<b;j++)
        {cin>>arr[j];

        }

        for(int j=0;j<d;j++)
        {
            cont[arr[j]]++;
        }

        int x=cont.size();

        int result=INT_MAX;

        for(int j=d;j<b;j++)
        {

            cont[arr[j-d]]--;

                if(cont[arr[j-d]]==0)
                    x--;

        cont[arr[j]]++;

            if(cont[arr[j]]==1)
                x++;

                if(result>x)
                    result=x;

        }

        cout<<min(result,x)<<"\n";

   }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,d;
    cin>>n>>k>>d;
    int arr[101];
    int cnt[101]={0};
    int cntt=0;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        cnt[arr[i]]++;
    }
        for(int i=n-d;i<n;i++){
        if(cnt[arr[i]]){
           cntt++;
           cnt[arr[i]]=0;

        }
    }
    printf("%d\n",cntt);
    }
    return 0;
}

#include <iostream>
#include <vector>
#include <bitset>

int main(){
  int nbCases;
  std::cin >> nbCases;

  for(int i = 0; i < nbCases; i++){
    int nbDays;
    std::cin >> nbDays;
    int nbShows;
    std::cin >> nbShows;
    int row;
    std::cin >> row;

    std::vector<int> program(nbDays);
    for(int j = 0; j < nbDays; j++)
      std::cin >> program[j];

    size_t answer = row;
    std::bitset<100> appeared;

    for(int j = 0; j < nbDays - row; j++){
      appeared.reset();

      for(int k = j; k < j + row; k++)
            appeared[program[k]] = true;

      if(appeared.count() < answer)
        answer = appeared.count();
    }
    std::cout << answer << std::endl;
  }
  return 0;
}

//#include "stdafx.h"
#include <bits\stdc++.h>

using namespace std;

int main()
{
	int T;
	cin >> T;
	for (int t = 0; t < T; ++t)
	{
		int n, k, d;
		cin >> n >> k >> d;
		vector<int> arr(n);
		for (int i = 0; i < n; ++i)
			arr[i] = 1;
		int v = 0, mxv = 1e9;
		map<int, int> intv;
		for (int i = 0; i < n; ++i)
		{
			if (intv[arr[i] - 1]++ == 0) ++v;
			if (i >= d && intv[arr[i - d] - 1]-- == 1) --v;
			if (i >= d - 1)
				mxv = min(mxv, v);
		}
		cout << mxv << '\n';
	}
	//system("pause");
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int

int main(){
flash;
int t;cin>>t;
while(t--){
int n,k,d;cin>>n>>k>>d;
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
set<int> s;
int ans=INT_MAX,sz;
for(int i=0;i<(n-d+1);i++){
    for(int j=i;j<n;j++)
        s.insert(a[j]);
sz = s.size();
ans = min(sz,ans);
s.clear();
}
cout<<ans<<endl;
}
return 0;
}

//ALL GLORY TO JESUS CHRIST
#include <bits/stdc++.h>
using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;

#define clr(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define frpn(x) freopen(#x ".in","r",stdin);freopen(#x ".out","w",stdout);
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define fornd(i, n) for(int i=(int)(n-1); i>=0; --i)
#define FOR(it,c) for ( __typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++ )

const int MOD = (int)1e9+7;

template <class T>
inline void rem(T &n){
   n = (-MOD <= n && n <= MOD) ? n : n%MOD ;
  if(n < 0) n += MOD;
}
//modular inverse
//inv(a,m) - inverse of a mod m
template <class T>
inline T inv(T a, T m){
 return 1<a ? m - inv(m%a, a)*m/a : 1;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifdef LOCAL
    clock_t tStart = clock();
#endif
    int t; cin >> t;
    while(t--) {
        int n, k, d; cin >> n >> k >> d;
        vi a(n+1);
        vi occ(4*k, 0);
        int unq = 0;
        for(int i=1; i<=n; ++i) cin >> a[i];
        for(int i=1; i<=d; ++i) {
            if(!occ[a[i]]) ++unq;
            ++occ[a[i]];
        }
        int res = k;
      //  cout << "unq: " << unq << "\n";
        for(int i=d+1; i<=n; ++i) {
     //       cout << "a[i]: " << a[i] << " a[i-d]: " << a[i-d] << "\n\n";
       //     cout << "before -> occ[a[i]]: " << occ[a[i]] << " occ[a[i-d]]: " << occ[a[i-d]] << "\n";
            if(!occ[a[i]])
                ++unq;
            ++occ[a[i]];
            res = min(res, unq);
            --occ[a[i-d]];
            if(!occ[a[i-d]])
                --unq;
       //     cout << "after -> occ[a[i]]: " << occ[a[i]] << " occ[a[i-d]]: " << occ[a[i-d]] << "\n";
         //   cout << "unq: " << unq << "\n\n";
           res = min(res, unq);
        }
        res = min(res, unq);
        cout << res << "\n";
    }
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * (clock() - tStart)/ CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}

/*

RFL <3
It's cold outside, lab is colder, no one is beside me. Only my brain is giving me heat....

*/

#include<bits/stdc++.h>

using namespace std;

#define sf scanf
#define pf printf
#define ll long long
#define fr(I,M,N) for(I=M;I<=N;I++)
#define fr_(I,M,N) for(I=M;I>=N;I--)
#define re return
#define sfn cin>>n
#define bal pf("bal\n")
#define pb push_back
#define ins insert
#define sz(X) X.size()
#define xx first
#define yy second
#define skip continue
#define memo(X,N) memset(X,N,sizeof(X))
#define all(X) X.begin(),X.end()
#define mp make_pair
#define pi acos(-1)

/*
#define nMX 5000000
#define pMX 500000
int pr[pMX+1],prnum[nMX+1];

int sieve()
{
    int i,j;
    for(i=1;i<=nMX;i++)
        prnum[i]=i+1;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            for(j=2*prnum[i]-1;j<=nMX;j+=prnum[i])
                    prnum[j]=-1;
    j=0;
    for(i=1;i<=nMX;i++)
        if(prnum[i]!=-1)
            pr[++j]=prnum[i];
    re j;
}*/

/*ll m_ncr[10001][10001];
ll ncr(ll i,ll j)
{
    if(j==1) re i;
    if(i==j) re 1;
    if(m_ncr[i][j]!=-1) re m_ncr[i][j];
    re m_ncr[i][j]=ncr(i-1,j) + ncr(i-1,j-1);
}*/

/*ll m_fact[21];
ll fact(ll i)
{
    if(i==1 || i==0) re 1;
    if(m_fact[i]!=-1) re m_fact[i];
    re m_fact[i]=i*fact(i-1);
}*/

ll flc[1000005],frc[1000005], mrst[200005], mren[200005];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll int i,j,x,y,n,m,cnt=0,k,g,flg,t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m>>k;
        ll in[n+1];
        fr(i,1,m)
        {
            flc[i]=frc[i]=0;
        }
        fr(i,1,n)
        {
            cin>>in[i];
            mrst[i]=mren[i]=0;
            if(!flc[in[i]])
            {
                mrst[i]=1;
                flc[in[i]]=1;
            }
        }
        fr_(i,n,1)
        {
            if(!frc[in[i]])
            {
                mren[i]=1;
                frc[in[i]]=1;
            }
        }
        ll a,b;
        a=b=1;
        ll an=1e18;
        x=1;
        while(b<=n)
        {
            if(b-a+1<k)
            {
                b++;
                x+=mrst[b];
            }
            else if(b-a+1==k)
            {
                an=min(an,x);
                x-=mren[a];
                a++;
            }
        }
        cout<<an<<endl;
    }
}

#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define in insert
using namespace std;
int main()
{
    int t,n,k,d;
    cin>>t;
    while(t--)
    {
        cin>>n>>k>>d;
        int m = 1000;
        int a[105];
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
        }
        int temp=1;
        for(int i=0; i<n; i++)
        {
            set<int>s;
            s.in(a[i]);
            int cnt = 1;
            bool t = true;
            for(int j=i+1; ;j++)
            {
                if(j>=n)
                {
                    t=false;
                    break;
                }
               s.in(a[j]);
               cnt++;
               if(cnt==d) break;
            }
            if(t){
            if(s.size()<m)
                m = s.size();
            s.clear();
                temp++;}
        }
        cout<<m<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>

using namespace std;

int main()
{
    int t;
    cin >> t;
    while(t--)
    {
        int n, k, d;
        cin >> n >> k >> d;
        vector<int> aj(n), check(k);
        for(int a = 0; a < k; a++)
            check[a] = -1;
        for(int a = 0; a < n; a++)
        {
            cin >> aj[a];
            aj[a]--;
        }
        int tot = INT_MAX, currTot = 0;
        for(int a = 0; a < d; a++)
        {
            if(check[aj[a]]==-1)
            {
                check[aj[a]] = a;
                currTot++;
            }
            else
            {
                check[aj[a]] = a;
            }
        }
        cout << currTot << endl;
        tot = min(tot, currTot);
        for(int a = 0; a < n-d; a++)
        {
            if(aj[a] == aj[a+d])
            {
                check[aj[a+d]] = a+d;
                continue;
            }
            else
            {
                if(check[aj[a]] == a)
                {
                    check[aj[a]] = -1;
                    currTot--;
                }
                if(check[aj[a+d]] == -1)
                {
                    check[aj[a+d]] = a+d;
                    currTot++;
                }
                else
                {
                    check[aj[a+d]] = a+d;
                }
                tot = min(tot, currTot);
            }
        }
        cout << tot << endl;
    }
}

/*
  BY_KUTBILIM
*/
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

#define endl '\n'
#define pb push_back
#define ff first
#define ss second

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const double eps = (double)1e-9;
const int inf = (int)1e9+7;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	while(t--){
		int n, k, d;
		cin >> n >> k >> d;
		int cnt[k+1] = {0};
		int a[n], c = 0;
		int ans;
		for(int i = 0; i < n; i++){
			cin >> a[i];
			cnt[a[i]]++;
			if(cnt[a[i]] == 1)c++;
			if(i == d - 1){
				ans = c;
			}
			else if(i >= d){
				cnt[a[i-d]]--;
				if(cnt[a[i-d]] == 0){
					c--;
				}
				ans = min(ans, c);
			}
		}
		cout << "ans = " << ans << endl;
	}

	return 0;
}

#include<iostream>
#include<set>
#include<cstring>
#include<queue>
using namespace std;

int a[200005];
int q3[200005];

int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin>>t;
	while(t--){
		set<int>q1;
		queue<int>q2;
		memset(q3,0,sizeof(q3));
		int n,k,d;
		cin>>n>>k>>d;
		int min1=k;
		for(int i=1;i<=n;i++){
			cin>>a[i];
			q1.insert(a[i]);
			q2.push(a[i]);
			q3[a[i]]++;
			while(q2.size()>d){
				int temp=q2.front();
				q2.pop();
				q3[temp]--;
				if(q3[temp]==0){
					q1.erase(temp);
				}
				min1=min(min1,(int)(q1.size()));
			}
		}
		if(q2.size()==d){
			min1=min(min1,(int)(q1.size()));
		}
		cout<<min1<<endl;

	}
	return 0;
}

#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
using namespace std;

int main(){
    int t;
    cin>>t;
    while(t--){
        long int n,k,d;
        cin>>n>>k>>d;
        long int A[n];
        for(int i=0; i<n; i++){
            cin>>A[i];
        }
        int c=0;
        map<int, int> memo;
        for(int i=1; i<=k; i++){
            memo[A[i]]=0;
        }
        int show[k];
        for(int i=0; i<d; i++){
            if(memo[A[i]]==0){
                memo[A[i]]++;
                c++;
            }
            else{
                memo[A[i]]++;
            }
        }
        int min_c=c;
        for(int i=d; i<n; i++){
            if(memo[A[i]]==0){
                memo[A[i]]=1;
                memo[A[i-d]]--;
                if(memo[A[i-d]]>0){
                    c++;
                }
            }
            else{
                memo[A[i]]++;
                memo[A[i-d]]--;
                if(memo[A[i-d]]>0){
                    c=c;
                }
                else{
                    c--;
                }
            }
            min_c = min(min_c,c);
        }
        cout<<c<<endl;

    }

    return 0;
}

/** Author: Dwai
 *  Omae wa mou shindeiru!
**/

#include <bits/stdc++.h>
using namespace std;

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define all(a) (a).begin(),(a).end()
#define fr(i,a,b) for (i = a; i <= b; i++)
#define frr(i,a,b) for (i = a; i >= b; i--)
#define rep(i,n) for (i = 0 ; i < n; i++)
#define repr(i,n) for (i = n - 1; i >= 0; i--)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define flushinput   cin.ignore(numeric_limits<streamsize>::max(),'\n');

void debug_out() { cerr << endl; }

void clock_out(){
  cerr<<"\nTime Elapsed : " << 1.0*clock() / CLOCKS_PER_SEC << " s\n";
}

void fileio(){
  freopen("/home/dwai/Desktop/cp/input.txt","r", stdin);
  freopen("/home/dwai/Desktop/cp/output.txt", "w", stdout);
  freopen("/home/dwai/Desktop/cp/debug.txt", "w", stderr);
}

void ofileio(){
  freopen("input.txt","r", stdin);
  freopen("output.txt", "w", stdout);
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << H;
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define fio() fileio()
#define ofio() fileio()
#define clock() clock_out()
#else
#define debug(...) 42
#define fio() 42
#define ofio() ofileio()
#define clock() 42
#endif

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<pll> vll;
typedef map<ll,ll> mll;

int IT_MAX = 1 << 20;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

void solve()
{
	ll n,k,d;
	cin>>n>>k>>d;

	ll a[n],i;

	rep(i,n) cin>>a[i];
	int m[k+1]={0};
	ll cnt=0;
	rep(i,d)
	{
		m[a[i]]++;
		if(m[a[i]]==1)
			cnt++;

	}

	ll ans=cnt;
	for(i=d;i<n;i++)
	{
		m[a[i]]++;
		m[a[i-d]]--;

		if(m[a[i]]==1)
			cnt++;
		if(m[a[i-d]]==0)
			cnt--;
		ans=min(ans,cnt);
	}
	cout<<ans<<"\n";
}
int main()
{
	fio();
	fast
	ll t=1;
	cin>>t;

	while(t--){
		solve();
	}
	return 0;
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdb> vpd;

#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define vv <vector<vector> >
#define mp make_pair
#define str(a, b) substr((a), (b))
#define rr return
#define r0 return 0
#define mi map<int>
#define ms map<string>
#define ml map<ll>
#define all_sum(a,b) accumulate((a),(b),0)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
void adskiy_razgon(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int MOD = 1e9+7; // 888244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
ll nod(ll a, ll b) {
    if(b > a) {
        swap(a, b);
    }
    while(b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll nok(ll a,ll b) {
    return a * b / nod(a, b);
}
void sp(ll a,double b) {
    cout << fixed << setprecision(a) << b;
}
ll binpow (ll a, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return binpow (a, n - 1) * a;
    }
    else {
        ll b = binpow (a, n / 2);
        return b * b;
    }
}

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
	read(t...);
}
template<class A> void read(vector<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}
string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vector<bool> v) {
    string res;
	FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
	FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}
template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
     write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void yes(bool ok) {
    print((ok ? "YES" : "Yes"));
}
void no(bool ok) {
    print((ok ? "NO" : "No"));

}
/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
ll a[100000];
void solve() {
    map<ll, ll> m;
    ll n, s, k;
    read(n, s, k);
    FOR(i, 1, n + 1) read(a[i]);
    ll ans = MOD;
    ll cnt = 0;
    FOR(i, 1, n + 1) {
        if(i >= k + 1) {
            m[a[i - k]]--;
            if(m[a[i - k]] == 0) cnt--;
            m[a[i]]++;
            if(m[a[i]] == 1) cnt++;
            ans = min(ans, cnt);
        }
        else {
            m[a[i]]++;
            if(m[a[i]] == 1) cnt++;
        }
    }
    ans = min(ans, cnt);
    print(ans);
}
int main(){
    adskiy_razgon();
    ll t = 1;
    cin >> t;
    for(int i = 1; i <= t; ++i) {
        //cout << "Case #" << i << ": ";
        solve();
    }
    r0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
//bool check(ll a[],ll d)
//{
//    ll ans=d;
//
//}
//ll binarySearch(ll arr[], ll l, ll r, ll& x)
//{
//    if (r >= l) {
//        ll mid = l + (r - l) / 2;
//
//        // If the element is present at the middle
//        // itself
//        if (arr[mid] == x)
//            return mid;
//
//        // If element is smaller than mid, then
//        // it can only be present in left subarray
//        if (arr[mid] > x)
//            return binarySearch(arr, l, mid - 1, x);
//
//        // Else the element can only be present
//        // in right subarray
//        return binarySearch(arr, mid + 1, r, x);
//    }
//
//    // We reach here when element is not
//    // present in array
//    return -1;
//}

int main() {
    ll t;
    cin>>t;
    while(t--)
    {
        ll n,k,d;
        cin>>n>>k>>d;
        ll a[n];
        for(ll i=0;i<n;i++)
        {
            cin>>a[i];
        }
        ll ans=INT_MAX;
        for(ll i=0;i<n;i++)
        {
            set<int> x;
            for(ll j=i;j<i+d;j++)
            {
                x.insert(a[j]);
            }
            ll si=x.size();
            ans=min(ans,si);
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod (ll)1000000000+7
#define fast std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
	fast;
	int t;cin>>t;
	while(t--)
	{
		ll n,k,d;cin>>n>>k>>d;
		ll hash[k+1]={0};
		ll a[n],i;
		ll p1=0,cnt=0,ans=0,final=n;
		for(i=0; i<n; i++)
		{
			cin>>a[i];
			hash[a[i]]++;
			if(hash[a[i]]==1)
					ans++;
			if(i+1==d)
				final=min(final,ans);
			else if(i+1>d)
			{
				hash[a[i+1-d]]--;
				if(hash[a[i+1-d]]==0)
					ans--;
				final=min(final,ans);
			}
		}
		cout<<final<<endl;
	}
}

#include <iostream>
using namespace std;
const int T=1e6+2;
int main() {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int t;cin>>t;
    while (t--){
        int n,k,d;cin>>n>>k>>d;
        int occ[T];
        for (int i=0 ; i<T; i++) occ[i]=0;
        int a[n+1];
        int cnt=0,r=0;
        for (int i=0 ;i<n; i++) cin>>a[i];
        for (int i=0 ; i<d ; i++){
            if (occ[a[i]]==0){
                cnt++;
            }
            occ[a[i]]++;
        }
        r=cnt;
        for (int i=d ;i<n; i++){
            occ[a[i-d]]--;
            if (occ[a[i-d]]==0) cnt--;
            if (occ[a[i]]==0) cnt++;
            r=min(r,cnt);
        }
        cout<<r<<'\n';
    }
    return 0;
}

/*check for overflows
check for the conditions in if.. (i<n or i<=n)
use fast input/output
keep it simple
keep practicing*/

#include <iostream>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;

const int MAXN = 2e5 + 5;
int a[MAXN];
int used[MAXN];

int main() {
	int q;
	cin >> q;
	while (q--) {
		int n, k, d;
		cin >> n >> k >> d;
		for (int i = 0; i < n; i++) {
			used[i] = 0;
			cin >> a[i];
			a[i]--;
		}
		int now = 0;
		for (int i = 0; i < d; i++) {
			if (!used[a[i]]) {
				now++;
			}
			used[a[i]]++;
		}
		int ans = now;
		//cout << now << "__\n";
		for (int i = 1; i < n - d + 1; i++) {
			if (a[i - 1] == a[i + d - 1])
				continue;
			used[a[i - 1]]--;
			used[a[i + d - 1]]++;
			//cout << i << " " << i + d - 1 << " " << now << "\n";
			if (used[a[i - 1]] == 0) {
				now--;
			}
			if (used[a[i + d - 1]] == 1) {
				now++;
			}
			//cout << now << "__\n";
			ans = min(ans, now);
		}
		cout << ans << "\n";
	}
	return 0;
}

                                   //BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<long long>
#define vs    vector<string>
#define dqi   deque<long long>
#define dqc   deque<char>
#define lii   list<long long>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mpss   map<string,ll>
#define mpi   map<int,int>
#define si    set<long long>
#define sc    set<char>
#define msi   multiset<long long>
#define ull    unsigned long long
#define ll   long long
#define ses   "\n"
#define X     first
#define Y     second
#define boroo  1e18

// Direction array
ll fx[]={1,-1,0,0};
ll fy[]={0,0,1,-1};
using namespace std;
//second element sort vector desen...
bool pairCompare2(const std::pair<ll, ll >& firstElem, const std::pair<ll, ll >& secondElem) {
  return firstElem.second > secondElem.second;

}
// Find max element of map with key.........
#define jokhonDorkrHobe map<int,int>::iterator best=max_element(mp.begin(),mp.end(),[] (const std::pair<char,ll>& a, const std::pair<char,ll>& b)->bool{ return a.second < b.second; } );
string ToStr( char c ) {
   return string( 1, c );
}

//main function is here........
int main(){
  ll t;
  cin>>t;
  while(t--){
    ll n,k,d;
    cin>>n>>k>>d;
    ll arr[n];
    si s,ss;
    for(ll i=0;i<n;i++){cin>>arr[i];}
    for(ll i=0;i<n-d;i++){
        for(ll j=i;j<i+d;j++){
            s.insert(arr[j]);
        }
        ss.insert(s.size());s.clear();
    }
    for(auto i:ss){cout<<i<<ses;break;}
  }
}
//Alhamdulillah

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
//typedef long long _int;
int m[200007];
int dp;
int num[200008];
const int inf=0x3f3f3f3f;
int main(){
int t;
scanf("%d",&t);
while(t--){
    int n,k,d;
    scanf("%d%d%d",&n,&k,&d);
    for(int i=0;i<n;i++){
        scanf("%d",&m[i]);
    }
    int minn=inf;
    //memset(dp,0,sizeof(0));

    dp=0;
    //memset(num,0,sizeof(0));
    for(int i=0;i<200000;i++){
        num[i]=0;
    }
    for(int i=0;i<d;i++)
    {
       // printf(" %d  %d  \n",m[i],num[m[i]]);
        if(num[m[i]]==0)
            dp++;
        num[m[i]]++;

    }

            minn=dp;
    for(int i=d;i<n;i++){
        if(num[m[i]]>0&&num[m[i-d]]==1&&m[i]!=m[i-d]){
                num[m[i]]++;
                dp=dp-1;
            }
            else
                if(num[m[i]]==0&&num[m[i-d]]>1&&m[i]!=m[i-d])
            {
                num[m[i]]++;
                    d++;
            }
            else
                if(m[i]!=m[i-d])
                num[m[i]]++;

        if(dp<minn)
            minn=dp;
           // printf("%d\n",dp);
    }
    printf("%d\n",minn);
}
}

#include <bits/stdc++.h>
#include <hash_map>
using namespace std ;
using namespace __gnu_cxx ;
///hash_map<int,int> Cnt ;
class PTree
{
#define INF 0x3f3f3f3f
#define MAXN 200005
#define N MAXN*40
public:
	struct Node {int L,R;int64_t data;}T[N] ;
	int root[MAXN+5],tot;
	int64_t max_val,min_val ;
	PTree(int _n=MAXN,int64_t min_val = 0,int64_t max_val=INF) {clear(_n,min_val,max_val);}
	inline void clear(int _n=MAXN,int64_t _min_val=0,int64_t _max_val=INF)
	{
		tot = 0 ; min_val = _min_val;max_val=_max_val ;
		T[0] = {0,0,0} ; for(int i(0);i<=_n;++i) root[i] = 0 ;
	}

	inline int newNode()
        {T[++tot] = {0,0,0} ; return tot ;}

	void insert(int rlast,int& rnow,int64_t l,int64_t r,int64_t p,int val = 1)
	{
		rnow = newNode();T[rnow]=T[rlast];T[rnow].data += val ;
		if(l == r) return ;
		int64_t mid((l+r)>>1) ;
		if(p<=mid) insert(T[rlast].L,T[rnow].L,l,mid,p,val) ;
		else insert(T[rlast].R,T[rnow].R,mid+1,r,p,val) ;
	}

	int _Rank(int pl,int pr,int64_t l,int64_t r,int64_t val)
	{
	    int64_t ans(0) ;
	    while(l!=r) {
            int64_t mid((l+r)>>1) ;
            int dson = T[T[pr].L].data - T[T[pl].L].data ;
            if(val<=mid) {pl = T[pl].L;pr = T[pr].L;;r = mid;}
            else {ans +=  dson ;pl = T[pl].R;pr = T[pr].R;l = mid+1;}
        }
		return ans ;
	}

	int64_t _Kth(int pl,int pr,int64_t l,int64_t r,int64_t k)
	{
        while(l!=r) {
            int d = T[T[pr].L].data-T[T[pl].L].data ;
            int64_t mid((l+r)>>1) ;
            if(d<k) {pl = T[pl].R; pr = T[pr].R; l = mid+1;k-=d;}
            else {pl = T[pl].L; pr = T[pr].L; r = mid;}
        }
        return l;
	}

	void insert(int i,int64_t d,int64_t val = 1)
	{
		root[i] = 0 ;
		if(val == 0) {root[i] = root[i-1] ; return ;}
		insert(root[i-1],root[i],min_val,max_val,d,val) ;
	}

	int64_t Rank(int l,int r,int64_t val)/**在区间[l,r]查询比val小的数有多少个*/
		{return _Rank(root[l-1],root[r],min_val,max_val,val) ;}

	int64_t Kth(int l,int r,int64_t k)/**在区间[l,r]查询第k小,例如 5 1 3 2 中Kth(3,4,1) = 2*/
		{return _Kth(root[l-1],root[r],min_val,max_val,k) ;}
#undef N
#undef MAXN
#undef INF
};
PTree tree;
int last[1000005],pre[1000005] ;
int main()
{
    int T,n,k,d ;
    scanf("%d",&T) ;
    while(T --> 0) {
        scanf("%d%d%d",&n,&k,&d) ;
        tree.clear(n+2,0,k+2) ;
        memset(last,0,sizeof(last[0])*(n+2)) ;
        memset(pre,0,sizeof(pre[0])*(n+2)) ;
        for(int i(1);i<=n;++i) {
            int buff ;
            scanf("%d",&buff) ;
            last[i] = pre[buff] ;
            pre[buff] = i ;
            tree.insert(i,last[i]) ;
        }
        int64_t ans = n ;
        for(int i(1);i+d-1<=n;++i) {
            ///cout<<i<<","<<i+d-1<<endl;
            ans = min(ans,tree.Rank(i,i+d-1,i)) ;
        }
        printf("%lld\n",ans) ;
    }
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll t;
    cin >> t;
    while(t--)
    {
        ll n,k,d;
        cin >> n >> k >> d;
        ll a[n];
        for(ll i=0;i<n;i++)
        {
            cin >> a[i];
        }
        ll ans=n,cnt=0,sum=0;
        ll b[k+1]={0};
        for(ll i=0;i<n;i++)
        {
            if(i>=d)
            {
                if(b[a[i-d]]==1)
                cnt--;
                b[a[i-d]]--;
            }
            b[a[i]]++;
            if(b[a[i]]<2)
            cnt++;
            if((i+1)%d==0)
            {
                ans = min(ans,cnt);
            }
        }
        cout << ans << "\n";
    }
}

#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
        int n,k,d,mi=999999;
        cin>>n>>k>>d;
        int a[n+1],m=0,p=d,j=1;
        set<int> s;
        for(int i=1;i<=n;i++)
            cin>>a[i];
        for(int i=1;i<=n/2;i++)
        {
              while(d--)
                 {
                     s.insert(a[j]);
                     j++;
                 }
                 m=s.size();
                 mi=min(mi,m);
                 s.clear();d=p;
        }
    cout<<mi<<endl;
    }
    return 0;
}

#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int INF =  1e9+9;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    int t;
    cin >> t;
    for (int j=0; j<t; ++j) {
        int n, k, d;
        cin >> n >> k >> d;
        int ans = n, now=0;
        vector <int> film(k+1);
        vector <int> a(n);

        for (int i=0; i<n; ++i)
            cin >> a[i], film[a[i]] = 0;

        for (int i=0; i<d; ++i) {
            if (!film[a[i]])
                ++now;
            film[a[i]]++;
        }

        for (int i=d; i<n; ++i) {
            film[a[i-d]]--;
            if (!film[a[i-d]])
                --now;
            if (!film[a[i]])
                ++now;
            film[a[i]]++;
            ans = min(ans, now);
        }
        cout << ans << "\n";
    }

    return 0;
}

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ll;
ll mod=1e9+7;
typedef pair<ll,ll> pll;
#define pb push_back
#define mp make_pair
#define acc (ios::sync_with_stdio(false),cin.tie(0))
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(ll i=0;i<n;i++)
#define per1(i,n) for(ll i=n-1;i>=0;i--)
ll ll_max(ll a,ll b,ll c){
	return max(a,max(b,c));
}
int int_max(int a,int b,int c){
	return max(a,max(b,c));
}
ll ll_min(ll a,ll b,ll c){
	return min(a,min(b,c));
}
int int_min(int a,int b,int c){
	return min(a,min(b,c));
}
void solve(){
	int n,k,d;
	cin>>n>>k>>d;
	int count=0,c=0;
	queue<int> q;
	int arr[k+1];
	int e;
	int er[k+1];
	memset(arr,0,sizeof(arr));
	memset(er,0,sizeof(er));
	for(int i=0;i<n;i++){
		cin>>e;
		if(i<d){
			q.push(e);
			if(arr[e]==0){
				count++;
			}
			arr[e]++;
		}
		else{
			er[i]=er[i-1];
			if(i==d){
				er[i]=count;
			}
			int r=q.front();
			q.pop();
			if(e!=r&&arr[r]==1){
				er[i]--;
			}
			if(arr[e]==1&&e!=r)
				er[i]=er[i]+1;
			if(count>er[i])
				count=er[i];
			q.push(e);
			arr[e]++;
			arr[r]--;
		}
	}
	cout<<count<<endl;
}
int main(){
    int t=1;
    cin>>t;
    while(t--){
    	solve();
    }
}

#include<bits/stdc++.h>
#include<set>
using namespace std;
typedef long long ll;
int main()
{
   int t;
   cin>>t;
   while(t--)
   {
       int n,d,k;
       cin>>n>>d>>k;
       int a[n];
       for(int i=0;i<n;i++)
        cin>>a[i];
       int x=INT_MAX;

       set <int> s;
       for(int i=0;i<n-k;i++)
       {
           for(int j=i;j<i+k;j++)
           {
              s.insert(a[j]);
           }
           int n=s.size();
           x=min(x,n);
           s.erase(s.begin(),s.end());

       }
       cout<<x<<endl;
   }
}

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<db,db> pdb;

typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<string> vs;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<pdb> vpd;

#define mp make_pair
#define ff first
#define ss second
#define sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define rall(x) (x).rbegin(), (x).rend()
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define vv <vector<vector> >
#define mp make_pair
#define str(a, b) substr((a), (b))
#define rr return
#define r0 return 0
#define mi map<int>
#define ms map<string>
#define ml map<ll>
#define all_sum(a,b) accumulate((a),(b),0)
#define F_OR(i, a, b, s) for (int i=(a); (s)>0?i<(b):i>(b); i+=(s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...) F_ORC(__VA_ARGS__)(__VA_ARGS__)
#define EACH(x, a) for (auto& x: a)
void adskiy_razgon(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
const int MOD = 1e9+7; // 888244353;
const int MX = 2e5+5;
const ll INF = 1e18;
const ld PI = acos((ld)-1);
const int xd[4] = {1,0,-1,0}, yd[4] = {0,1,0,-1};
ll nod(ll a, ll b) {
    if(b > a) {
        swap(a, b);
    }
    while(b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}
ll nok(ll a,ll b) {
    return a * b / nod(a, b);
}
void sp(ll a,double b) {
    cout << fixed << setprecision(a) << b;
}
ll binpow (ll a, ll n) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 1) {
        return binpow (a, n - 1) * a;
    }
    else {
        ll b = binpow (a, n / 2);
        return b * b;
    }
}

template<class A> void read(vector<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) {
    cin >> x;
}
void read(double& d) {
    string t;
    read(t);
    d=stod(t);
}
void read(long double& d) {
    string t;
    read(t);
    d=stold(t);
}
template<class H, class... T> void read(H& h, T&... t) {
    read(h);
	read(t...);
}
template<class A> void read(vector<A>& x) {
    EACH(a, x)
        read(a);
}
template<class A, size_t S> void read(array<A, S>& x) {
    EACH(a, x)
        read(a);
}
string to_string(char c) {
    return string(1, c);
}
string to_string(bool b) {
    return b?"true":"false";
}
string to_string(const char* s) {
    return string(s);
}
string to_string(string s) {
    return s;
}
string to_string(vector<bool> v) {
    string res;
	FOR(sz(v))
        res+=char('0'+v[i]);
    return res;
}

template<size_t S> string to_string(bitset<S> b) {
    string res;
	FOR(S)
        res+=char('0'+b[i]);
    return res;
}
template<class T> string to_string(T v) {
    bool f=1;
    string res;
    EACH(x, v) {
        if(!f)
            res+=' ';
        f=0;
        res+=to_string(x);
    }
    return res;
}
template<class A> void write(A x) {
    cout << to_string(x);
}
template<class H, class... T> void write(const H& h, const T&... t) {
    write(h);
    write(t...);
}
void print() {
     write("\n");
}
template<class H, class... T> void print(const H& h, const T&... t) {
    write(h);
    if(sizeof...(t))
        write(' ');
    print(t...);
}

void yes(bool ok) {
    print((ok ? "YES" : "Yes"));
}
void no(bool ok) {
    print((ok ? "NO" : "No"));

}
/*
⣿⣿⣿⣿⣿⣿⡷⣯⢿⣿⣷⣻⢯⣿⡽⣻⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣇⠸⣿⣿⣆⠹⣿⣿⢾⣟⣯⣿⣿⣿⣿⣿⣿⣽⣻⣿⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣻⣽⡿⣿⣎⠙⣿⣞⣷⡌⢻⣟⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣿⣿⡄⠹⣿⣿⡆⠻⣿⣟⣯⡿⣽⡿⣿⣿⣿⣿⣽⡷⣯⣿⣿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣷⣿⣿⣿⡀⠹⣟⣾⣟⣆⠹⣯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢠⡘⣿⣿⡄⠉⢿⣿⣽⡷⣿⣻⣿⣿⣿⣿⡝⣷⣯⢿⣿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣯⢿⣾⢿⣿⡄⢄⠘⢿⣞⡿⣧⡈⢷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡇⢸⣧⠘⣿⣷⠈⣦⠙⢿⣽⣷⣻⣽⣿⣿⣿⣿⣌⢿⣯⢿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⣟⣯⣿⢿⣿⡆⢸⡷⡈⢻⡽⣷⡷⡄⠻⣽⣿⣿⡿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⣿⣏⢰⣯⢷⠈⣿⡆⢹⢷⡌⠻⡾⢋⣱⣯⣿⣿⣿⣿⡆⢻⡿⣿⣿⣿
⣿⣿⣿⣿⣿⣿⡎⣿⢾⡿⣿⡆⢸⣽⢻⣄⠹⣷⣟⣿⣄⠹⣟⣿⣿⣟⣿⣿⣿⣿⣿⣿⣽⣿⣿⣿⡇⢸⣯⣟⣧⠘⣷⠈⡯⠛⢀⡐⢾⣟⣷⣻⣿⣿⣿⡿⡌⢿⣻⣿⣿
⣿⣿⣿⣿⣿⣿⣧⢸⡿⣟⣿⡇⢸⣯⣟⣮⢧⡈⢿⣞⡿⣦⠘⠏⣹⣿⣽⢿⣿⣿⣿⣿⣯⣿⣿⣿⡇⢸⣿⣿⣾⡆⠹⢀⣠⣾⣟⣷⡈⢿⣞⣯⢿⣿⣿⣿⢷⠘⣯⣿⣿
⣿⣿⣿⣿⣿⣿⣿⡈⣿⢿⣽⡇⠘⠛⠛⠛⠓⠓⠈⠛⠛⠟⠇⢀⢿⣻⣿⣯⢿⣿⣿⣿⣷⢿⣿⣿⠁⣾⣿⣿⣿⣧⡄⠇⣹⣿⣾⣯⣿⡄⠻⣽⣯⢿⣻⣿⣿⡇⢹⣾⣿
⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⡽⡇⢸⣿⣿⣿⣿⣿⣞⣆⠰⣶⣶⡄⢀⢻⡿⣯⣿⡽⣿⣿⣿⢯⣟⡿⢀⣿⣿⣿⣿⣿⣧⠐⣸⣿⣿⣷⣿⣿⣆⠹⣯⣿⣻⣿⣿⣿⢀⣿⢿
⣿⣿⣿⣿⣿⣿⣿⣿⠘⣯⡿⡇⢸⣿⣿⣿⣿⣿⣿⣿⣧⡈⢿⣳⠘⡄⠻⣿⢾⣽⣟⡿⣿⢯⣿⡇⢸⣿⣿⣿⣿⣿⣿⡀⢾⣿⣿⣿⣿⣿⣿⣆⠹⣾⣷⣻⣿⡿⡇⢸⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡇⢹⣿⠇⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣄⠻⡇⢹⣆⠹⣟⣾⣽⣻⣟⣿⣽⠁⣾⣿⣿⣿⣿⣿⣿⣇⣿⣿⠿⠛⠛⠉⠙⠋⢀⠁⢘⣯⣿⣿⣧⠘⣿
⣿⣿⣿⣿⣿⣿⣿⣿⣿⡈⣿⡃⢼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣦⡙⠌⣿⣆⠘⣿⣞⡿⣞⡿⡞⢠⣿⣿⣿⣿⣿⡿⠛⠉⠁⢀⣀⣠⣤⣤⣶⣶⣶⡆⢻⣽⣞⡿⣷⠈⣿
⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⠘⠁⠉⠉⠉⠉⠉⠉⠉⠉⠉⠙⠛⠛⢿⣄⢻⣿⣧⠘⢯⣟⡿⣽⠁⣾⣿⣿⣿⣿⣿⡃⢀⢀⠘⠛⠿⢿⣻⣟⣯⣽⣻⣵⡀⢿⣯⣟⣿⢀⣿
⣿⣿⣿⣟⣿⣿⣿⣿⣶⣶⡆⢀⣿⣾⣿⣾⣷⣿⣶⠿⠚⠉⢀⢀⣤⣿⣷⣿⣿⣷⡈⢿⣻⢃⣼⣿⣿⣿⣿⣻⣿⣿⣿⡶⣦⣤⣄⣀⡀⠉⠛⠛⠷⣯⣳⠈⣾⡽⣾⢀⣿
⣿⢿⣿⣿⣻⣿⣿⣿⣿⣿⡿⠐⣿⣿⣿⣿⠿⠋⠁⢀⢀⣤⣾⣿⣿⣿⣿⣿⣿⣿⣿⣌⣥⣾⡿⣿⣿⣷⣿⣿⢿⣷⣿⣿⣟⣾⣽⣳⢯⣟⣶⣦⣤⡾⣟⣦⠘⣿⢾⡁⢺
⣿⣻⣿⣿⡷⣿⣿⣿⣿⣿⡗⣦⠸⡿⠋⠁⢀⢀⣠⣴⢿⣿⣽⣻⢽⣾⣟⣷⣿⣟⣿⣿⣿⣳⠿⣵⣧⣼⣿⣿⣿⣿⣿⣾⣿⣿⣿⣿⣿⣽⣳⣯⣿⣿⣿⣽⢀⢷⣻⠄⠘
⣿⢷⣻⣿⣿⣷⣻⣿⣿⣿⡷⠛⣁⢀⣀⣤⣶⣿⣛⡿⣿⣮⣽⡻⣿⣮⣽⣻⢯⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⢀⢸⣿⢀⡆
⠸⣟⣯⣿⣿⣷⢿⣽⣿⣿⣷⣿⣷⣆⠹⣿⣶⣯⠿⣿⣶⣟⣻⢿⣷⣽⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢀⣯⣟⢀⡇
⣇⠹⣟⣾⣻⣿⣿⢾⡽⣿⣿⣿⣿⣿⣆⢹⣶⣿⣻⣷⣯⣟⣿⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⢀⡿⡇⢸⡇
⣿⣆⠹⣷⡻⣽⣿⣯⢿⣽⣻⣿⣿⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠇⢸⣿⠇⣼⡇
⡙⠾⣆⠹⣿⣦⠛⣿⢯⣷⢿⡽⣿⣿⣿⣿⣆⠻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠃⠎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⢀⣿⣾⣣⡿⡇
⣿⣷⡌⢦⠙⣿⣿⣌⠻⣽⢯⣿⣽⣻⣿⣿⣿⣧⠩⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⢰⢣⠘⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠃⢀⢀⢿⣞⣷⢿⡇
⣿⣽⣆⠹⣧⠘⣿⣿⡷⣌⠙⢷⣯⡷⣟⣿⣿⣿⣷⡀⡹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣈⠃⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⢀⣴⡧⢀⠸⣿⡽⣿⢀
⢻⣽⣿⡄⢻⣷⡈⢿⣿⣿⢧⢀⠙⢿⣻⡾⣽⣻⣿⣿⣄⠌⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠛⢁⣰⣾⣟⡿⢀⡄⢿⣟⣿⢀
⡄⢿⣿⣷⢀⠹⣟⣆⠻⣿⣿⣆⢀⣀⠉⠻⣿⡽⣯⣿⣿⣷⣈⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⢀⣠⠘⣯⣷⣿⡟⢀⢆⠸⣿⡟⢸
⣷⡈⢿⣿⣇⢱⡘⢿⣷⣬⣙⠿⣧⠘⣆⢀⠈⠻⣷⣟⣾⢿⣿⣆⠹⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠋⣠⡞⢡⣿⢀⣿⣿⣿⠇⡄⢸⡄⢻⡇⣼
⣿⣷⡈⢿⣿⡆⢣⡀⠙⢾⣟⣿⣿⣷⡈⠂⠘⣦⡈⠿⣯⣿⢾⣿⣆⠙⠻⠿⠿⠿⠿⡿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠿⠛⢋⣠⣾⡟⢠⣿⣿⢀⣿⣿⡟⢠⣿⢈⣧⠘⢠⣿
⣿⣿⣿⣄⠻⣿⡄⢳⡄⢆⡙⠾⣽⣿⣿⣆⡀⢹⡷⣄⠙⢿⣿⡾⣿⣆⢀⡀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⢀⣀⣠⣴⡿⣯⠏⣠⣿⣿⡏⢸⣿⡿⢁⣿⣿⢀⣿⠆⢸⣿
⣿⣿⣿⣿⣦⡙⣿⣆⢻⡌⢿⣶⢤⣉⣙⣿⣷⡀⠙⠽⠷⠄⠹⣿⣟⣿⣆⢙⣋⣤⣤⣤⣄⣀⢀⢀⢀⢀⣾⣿⣟⡷⣯⡿⢃⣼⣿⣿⣿⠇⣼⡟⣡⣿⣿⣿⢀⡿⢠⠈⣿
⣿⣿⣿⣿⣿⣷⣮⣿⣿⣿⡌⠁⢤⣤⣤⣤⣬⣭⣴⣶⣶⣶⣆⠈⢻⣿⣿⣆⢻⣿⣿⣿⣿⣿⣿⣷⣶⣤⣌⣉⡘⠛⠻⠶⣿⣿⣿⣿⡟⣰⣫⣴⣿⣿⣿⣿⠄⣷⣿⣿⣿
*/
int a[100000];
void solve() {
    map<int, int> m;
    int n, s, k;
    read(n, s, k);
    FOR(i, 1, n + 1) read(a[i]);
    int ans = MOD;
    int cnt = 0;
    FOR(i, 1, n + 1) {
        if(i >= k + 1) {
            m[a[i - k]]--;
            if(m[a[i - k]] == 0) cnt--;
            m[a[i]]++;
            if(m[a[i]] == 1) cnt++;
            ans = min(ans, cnt);
        }
        else {
            m[a[i]]++;
            if(m[a[i]] == 1) cnt++;
        }
    }
    ans = min(ans, cnt);
    print(ans);
}
int main(){
    adskiy_razgon();
    ll t = 1;
    cin >> t;
    for(int i = 1; i <= t; ++i) {
        //cout << "Case #" << i << ": ";
        solve();
    }
    r0;
}

#include<bits/stdc++.h>
#define ull unsigned long long
#define ll long long
const int inf=1e9+7;
const int maxn=1e6+5;
using namespace std;

int ma[maxn];
int vis[maxn];
int main()
{
    int  t ;
    scanf("%d",&t);
    int n,k,d;
    while(t--)
    {
       // set<int>s;
        map<int,int>mp;
        scanf("%d%d%d",&n,&k,&d);
        for(int i=1;i<=n;i++){
            scanf("%d",&ma[i]);
        }
        if(d==1){
            cout<<1<<endl;continue;
        }
        int ant=0;
        for(int i=1;i<=d;i++){
            //s.insert(ma[i]);
            if(mp[ma[i]]==0){
                ant++;
            }
            mp[ma[i]]++;
        }
        //set<int>::iterator it;
        for(int i=d+1;i<=n;i++)
        {
            if(mp[ma[i-d]]>1){
                mp[ma[i-d]]--;
                if(mp[ma[i]]==0){
                    ant++;
                }
                mp[ma[i]]++;
            }
            else{
                mp[ma[i-d]]=0;
                ant--;
                if(mp[ma[i]]==0){
                    ant++;
                }
                mp[ma[i]]++;
            }
           // mp[ma[i]]++;
            //s.insert(ma[i]);
            //int t=s.size();
            //ant=min(ant,t);
        }
        printf("%d\n",ant);
    }
    return 0;
}

#include <bits/stdc++.h>
using namespace std;
#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ALL(x) x.begin(),x.end()
#define SZ(x) x.size()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PI;
int dx[] = { -1, 1, 0, 0, -1, 1, -1, 1 };
int dy[] = { 0, 0, -1, 1, -1, 1, 1, -1 };
const int oo = 2e9 + 5;
const int N = 1e6;
int t, n, k, d , a[N];
int main() {
    io
    cin >> t;
    while(t--) {
        map <int,int > f;
        cin >> n >> k >> d;
        //int a[ n + 5 ] = {0};
        for(int i = 0; i < n; i++)
            cin >> a[i];
        set<int > s ;
        int l = 0, r = d - 1, cnt = 0;
        for(int i = l; i <= r; i++) {
            s.insert(a[i]) ;
            f[a[i]]++;
        }
        int ans = SZ(s);
        while(r < n) {
            f[a[l]]--;
            if(f[a[l]] == 0) s.erase(a[l]) ;
            l++; r++;
            s.insert(a[r]) ;
            f[a[r]]++;
            ans = min(ans,(int)SZ(s));
        }
        cout << ans << "\n";
    }
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const int MX = 2e5+7;
int gg[MX];
int cnt[MX];
int main()//1247B
{
    int t;
    cin>>t;
    while(t--)
    {
        int n, k, d;
        cin>>n>>k>>d;
        memset(cnt, 0, 4*(n+2));
        for(int i = 1; i <= n; ++i)
            scanf("%d", &gg[i]);
        int tmp = 0;
        for(int i = 1; i <= d; ++i)
        {
            cnt[gg[i]]++;
            if(cnt[gg[i]] == 1)
                tmp++;
        }
        int ans = tmp;
        for(int i = d+1; i <= n; ++i)
        {
            cnt[gg[i-d]]--;
            cnt[gg[i]]++;
            if(cnt[gg[i]] == 1)
                tmp++;
            if(!cnt[gg[i-d]])
                tmp--;
            ans = min(ans, tmp);
        }
        cout<<ans<<endl;
    }
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define MAXI 2000005
#define MAX 300006
ll arr[MAX+10];
ll last[MAX+10];
ll tree[(4*MAX)+10];
void reset(ll x)
{
    for(ll i=0;i<=4*x+19;i++)
    {
        if(3*i<=x+19){
            arr[i]=0;
            last[i]=-1;
        }
        tree[i]=0;
    }
}
void update(ll nd,ll b,ll e,ll i,ll val)
{
    if(b>i or i>e) return;
    else if(b>=i && e<=i)
    {
        tree[nd]+=val;
        return;
    }
    ll lf=2*nd;
    ll rt=lf+1;
    ll mid=(b+e)/2;
    update(lf,b,mid,i,val);
    update(rt,mid+1,e,i,val);
    tree[nd]=tree[lf]+tree[rt];
}
ll query(ll nd,ll b,ll e,ll i,ll j)
{
    if(b>j or e<i) return 0;
    else if(b>=i && e<=j) return tree[nd];
    ll lf=2*nd;
    ll rt=lf+1;
    ll mid=(b+e)/2;
    ll q1=query(lf,b,mid,i,j);
    ll q2=query(rt,mid+1,e,i,j);
    return q1+q2;
}
int main()
{
    ll n,q,t;
    scanf("%lld",&t);
    reset(200005);
    ll ok=0;
    for(ll test=1;test<=t;test++)
    {
        vector< pair<ll,pair<ll,ll> > >v;
        ll k,d;
        scanf("%lld %lld %lld",&n,&k,&d);
        reset(n);
        map<ll,ll>mp;
        mp.clear();
        ll cnt=1;
        for(ll i=1;i<=n;i++)
        {
            scanf("%lld",&arr[i]);
            if(mp[arr[i]]==0)
            {
                mp[arr[i]]=cnt;
                cnt++;
            }
        }
        ll lf,rt;
        for(ll i=1;;i++)
        {
            lf=i;
            rt=i+d-1;
            if(rt>n)
            {
                break;
            }
            v.push_back(make_pair(rt,make_pair(lf,i)));
        }
        sort(v.begin(),v.end());
        ll j=0;
        ll ans=1000000;
        ll q=v.size();
        for(ll i=1;i<=n;i++)
        {
            ll x=last[mp[arr[i]]];
            //cout<<x<<endl;
            if(x==-1)
            {
                ///cout<<"ankon"<<endl;
                last[mp[arr[i]]]=i;
                //cout<<i<<endl;
                update(1,1,n,i,1);
                ///cout<<"ho"<<endl;
            }
            else if(x!=-1)
            {
                ///cout<<x<<endl;
                update(1,1,n,x,-1);
                last[mp[arr[i]]]=i;
                ///cout<<i<<endl;
                update(1,1,n,i,1);
            }
            ///cout<<"go"<<endl;
            while(1){
                ll r=v[j].first;
                ll l=v[j].second.first;
                ll idx=v[j].second.second;
                ///cout<<l<<" "<<r<<endl;
                if(r!=i or j>q)
                {
                    break;
                }
                ll y=query(1,1,n,l,r);
                //cout<<x<<endl;
                ///cout<<l<<" "<<r<<" "<<x<<endl;
                ans=min(ans,y);
                j++;
            }
        }
        if(ans==1000000) ans=0;
        printf("%lld\n",ans);
    }
    return 0;
}

#include <iostream>
#include <cstdio>
#include <memory.h>
using namespace std;
int arr[1000010];
int arrs[1000010];
int main(){
	int s,n,k,d;
	scanf("%d",&s);
	while(s--){
		scanf("%d %d %d",&n,&k,&d);
		for(int i=0;i<n;i++){
			scanf("%d",&arrs[i]);
		}
		int days=0;
		int gs=1;
		int nums=99999999;
		//16 7 8
		for(int i=0,j=0,index=0;index<n;){

			if(i-j<=d-1){
				if(arr[arrs[i]]==0){//Èç¹ûÃ»ÓÐ¹ºÂò¹ý£¬¾Í¼ÓÒ»ÕÅÓ°Æ¬
					arr[arrs[i]]++;//±íÊ¾¹ºÂò
					gs++;
				}
				i++;
			}
			if(i-j==d){
				if(arr[arrs[j]]==1){
					gs--;
				}
				arr[arrs[j]]--;
				j++;
			}
			days++;
			if(days==d){
				nums=min(nums,gs);
				days--;
				if(index==n){
					break;
				}
			}
			index++;
		}
		cout<<nums<<endl;
		memset(arr,0,sizeof(arr));
	}
	return 0;
}

/*
4
5 2 2
1 2 1 2 1
10 3 3
3 3 3 2 2 2 1 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3

*/