import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Round260 {

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }
}

/*
 * Am I wrong for thinking out the box from where I stay? Am I wrong for saying
 * that I choose another way?
 *
 * I ain't trying to do what everybody else doing Just cause everybody doing
 * what they all do
 *
 * If one thing I know, I'll fall but I'll grow
 *
 * I'm walking down this road of mine, this road that I call home
 *
 * So am I wrong?
 */

class TaskB {

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        boolean resA[] = new boolean[n];
        boolean resB[] = new boolean[n];

        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

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

        Arrays.fill(resA, 0, pA, true);

        int k = n / 2;

        StringBuilder ansA = new StringBuilder();
        StringBuilder ansB = new StringBuilder();
        char temp;

        for (int i = 0; i < n; i++) {
            temp = resA[i] || i < k ? '1' : '0';
            ansA.append(temp);

            temp = resB[i] || i < k ? '1' : '0';
            ansB.append(temp);
        }

        out.println(ansA);
        out.println(ansB);

    }
}

/*
 * For thinking that we could be something for real? Now am I wrong?
 *
 * For trying to reach the things that I can't see?
 *
 * But that's just how I feel,
 *
 * That's just how I feel
 *
 * That's just how I feel
 *
 * Trying to reach the things that I can't see
 */

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Round260 {

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }
}

/*
 * Am I wrong for thinking out the box from where I stay? Am I wrong for saying
 * that I choose another way?
 *
 * I ain't trying to do what everybody else doing Just cause everybody doing
 * what they all do
 *
 * If one thing I know, I'll fall but I'll grow
 *
 * I'm walking down this road of mine, this road that I call home
 *
 * So am I wrong?
 */

class TaskB {

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        boolean resA[] = new boolean[n];
        boolean resB[] = new boolean[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

        int pA = n - 1;
        for (int i = 0; b[i] < a[pA] && i < n; i++) {
            resB[i] = true;
            pA--;
        }

        Arrays.fill(resA, 0,pA+1,true);

        int k = n / 2;

        StringBuilder ansA = new StringBuilder();
        StringBuilder ansB = new StringBuilder();
        char temp;

        for (int i = 0; i < n; i++) {
            temp = resA[i] || i < k ? '1' : '0';
            ansA.append(temp);

            temp = resB[i] || i < k ? '1' : '0';
            ansB.append(temp);
        }

        out.println(ansA);
        out.println(ansB);

    }
}

/*
 * For thinking that we could be something for real? Now am I wrong?
 *
 * For trying to reach the things that I can't see?
 *
 * But that's just how I feel,
 *
 * That's just how I feel
 *
 * That's just how I feel
 *
 * Trying to reach the things that I can't see
 */

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;

public class Round260 {

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(in, out);
        out.close();
    }
}

/*
 * Am I wrong for thinking out the box from where I stay? Am I wrong for saying
 * that I choose another way?
 *
 * I ain't trying to do what everybody else doing Just cause everybody doing
 * what they all do
 *
 * If one thing I know, I'll fall but I'll grow
 *
 * I'm walking down this road of mine, this road that I call home
 *
 * So am I wrong?
 */

class TaskB {

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];

        boolean resA[] = new boolean[n];
        boolean resB[] = new boolean[n];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }

        int pA = n-1;
        for (int i = 0; i < n; i++) {
            if (b[i] < a[pA])
            {
                resB[i] = true;
                pA--;
            }
            else
            {
                break;
            }
        }

        for (int i = 0; i <= pA; i++) {
            resA[i] = true;
        }

        int k = n/2;

        StringBuilder ansA = new StringBuilder();
        StringBuilder ansB = new StringBuilder();
        char temp;

        for (int i = 0; i < n; i++) {
            temp = resA[i] || i < k ? '1' : '0';
            ansA.append(temp);

            temp = resB[i] || i < k ? '1' : '0';
            ansB.append(temp);
        }

        out.println(ansA);
        out.println(ansB);

    }
}

/*
 * For thinking that we could be something for real? Now am I wrong?
 *
 * For trying to reach the things that I can't see?
 *
 * But that's just how I feel,
 *
 * That's just how I feel
 *
 * That's just how I feel
 *
 * Trying to reach the things that I can't see
 */

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


//package R222;

import java.io.*;
import java.util.*;

/**
 *
 * @coder Altynbek Nurgaziyev
 */
public class B {

        void solution() throws Exception {
                int n = in.nextInt(), a[] = new int[n], b[] = new int[n];
                for (int i = 0; i < n; i++) {
                        a[i] = in.nextInt();
                        b[i] = in.nextInt();
                }
                boolean[] pa = new boolean[n];
                boolean[] pb = new boolean[n];
                for (int i = 0; i < n / 2; i++) {
                        pa[i] = true;
                        pb[i] = true;
                }
                int ia = 0, ib = 0;
                for (int i = 0; i < n; i++) {
                        if (a[ia] < b[ib]) {
                                pa[ia++] = true;
                        } else {
                                pb[ib++] = true;
                        }
                }
                for (int i = 0; i < n; i++) {
                        if (pa[i]) {
                                out.print(1);
                        } else {
                                out.print(0);
                        }
                }
                out.println();
                for (int i = 0; i < n; i++) {
                        if (pb[i]) {
                                out.print(1);
                        } else {
                                out.print(0);
                        }
                }
                out.println();
        }

        public static void main(String[] args) throws Exception {
                new B().run();
        }

        Scanner in;
        PrintWriter out;

        void run() throws Exception {
                in = new Scanner(new InputStreamReader(System.in));
                out = new PrintWriter(new OutputStreamWriter(System.out));
                solution();
                out.flush();
        }

        class Scanner {

                final BufferedReader br;
                StringTokenizer st;

                Scanner(InputStreamReader stream) {
                        br = new BufferedReader(stream);
                }

                String next() throws Exception {
                        while (st == null || !st.hasMoreTokens()) {
                                st = new StringTokenizer(br.readLine());
                        }
                        return st.nextToken();
                }

                Integer nextInt() throws Exception {
                        return Integer.parseInt(next());
                }

                Long nextLong() throws Exception {
                        return Long.parseLong(next());
                }

                Double nextDouble() throws Exception {
                        return Double.parseDouble(next());
                }
        }
}


//package Round_222;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {

    void solve() throws Exception{
        int n = in.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for (int i = 0; i<n; i++) {
            a[i] = in.nextInt();
            b[i] = in.nextInt();
        }
        byte f0[] = new byte[n];
        byte f1[] = new byte[n];
        int l = 0, r = 0;
        for (int i = 0; i < n; i++)
            if (a[l] < b[r]){
                f0[l++] = 1;
            } else {
                f1[r++] = 1;
            }
        for (int i = 0; i<n/2; i++) {
            f0[i] = 1;
            f1[i] = 1;
        }
        for (int i = 0; i<n; i++)
            out.print(f0[i]);
        out.println();
        for (int i = 0; i<n; i++)
            out.print(f1[i]);
    }

    String input = "";
    String output = "";
    FastScanner in;
    PrintWriter out;

    void run() throws Exception {
        if (input.length() == 0) {
            in = new FastScanner(System.in);
        } else {
            in = new FastScanner(new File(input));
        }
        if (output.length() == 0) {
            out = new PrintWriter(System.out);
        } else {
            out = new PrintWriter(new File(output));
        }

        solve();

        out.close();

    }

    public static void main(String[] args) throws Exception {
        new B().run();
    }

    class FastScanner {

        BufferedReader bf;
        StringTokenizer st;

        public FastScanner(InputStream is) {
            bf = new BufferedReader(new InputStreamReader(is));
        }

        public FastScanner(File fr) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fr));
        }

        public String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(bf.readLine());
                }
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

        public int[] readIntArray(int length) {
            int arr[] = new int[length];
            for (int i = 0; i<length; i++)
                arr[i] = nextInt();
            return arr;
        }
    }
}


import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
			b[i]=in.nextInt();
		}
		int fi[]=new int[n];
		int se[]=new int[n];
		int max_k=n/2-1;

		int posa=0;
		int posb=0;
		int pos=0;
		while(pos<n){
			if(a[posa]<b[posb]){
				fi[posa]=1;
				posa++;
				pos++;
			}else{
				se[posb]=1;
				posb++;
				pos++;
			}
		}
		for(int i=0;i<=max_k;i++){
			fi[i]=1;
			se[i]=1;
		}
		String resultFi="";
		String resultSe="";
		for(int i=0;i<n;i++){
			resultFi+=fi[i];
			resultSe+=se[i];
		}
		System.out.println(resultFi);
		System.out.println(resultSe);
	}
}


import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int a[]=new int[n];
		int b[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=in.nextInt();
			b[i]=in.nextInt();
		}
		int fi[]=new int[n];
		int se[]=new int[n];
		int max_k=n/2-1;

		int posa=0;
		int posb=0;
		int pos=0;
		while(pos<n){
			if(a[posa]<b[posb]){
				fi[posa]=1;
				posa++;
				pos++;
			}else{
				se[posb]=1;
				posb++;
				pos++;
			}
		}
		for(int i=posa;i<=max_k;i++){
			fi[i]=1;
		}
		for(int i=posb;i<=max_k;i++){
			se[i]=1;
		}
		for(int i=0;i<n;i++)
			System.out.print(fi[i]);
		System.out.println();
		for(int i=0;i<n;i++)
			System.out.print(se[i]);

	}
}


import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        // A player may go to final iff
        // One or two of the followings hold
        // 1) the rank in its semifinal is better than or equal to n/2
        // 2) the rank in total is better than or equal to n-2
        int n = nextInt();
        StringBuilder resultOfA = new StringBuilder();
        StringBuilder resultOfB = new StringBuilder();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++){
            int[] inp = nextIntArray();
            a[i] = inp[0];
            b[i] = inp[1];
        }
        int indA = 0;
        int indB = 0;
        int total = 0; // how many players we have seen so far
        while (total <= n-2){
            if (a[indA] < b[indB]){
                resultOfA.append("1");
                indA ++;
            }
            if (a[indA] > b[indB]){
                resultOfB.append("1");
                indB ++;
            }
            total ++;
        }
        while (indA + 1 <= n / 2){
            resultOfA.append("1");
            indA ++;
        }
        while (indB + 1 <= n / 2){
            resultOfB.append("1");
            indB ++;
        }

        while (indA < n){
            resultOfA.append("0");
            indA ++;
        }
        while (indB < n){
            resultOfB.append("0");
            indB ++;
        }
        out.append(resultOfA);
        out.append("\n");
        out.append(resultOfB);

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static long nextLong(){
        return Long.parseLong(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}


import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        // A player may go to final iff
        // One or two of the followings hold
        // 1) the rank in its semifinal is better than or equal to n/2
        // 2) the rank in total is better than or equal to n-2
        int n = nextInt();
        StringBuilder resultOfA = new StringBuilder();
        StringBuilder resultOfB = new StringBuilder();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++){
            int[] inp = nextIntArray();
            a[i] = inp[0];
            b[i] = inp[1];
        }
        int indA = 1;
        int indB = 1;
        int total = 0; // how many players we have seen so far
        resultOfA.append(1);
        resultOfB.append(1);
        while (total + 1 <= n-2){
            if (a[indA] < b[indB]){
                resultOfA.append("1");
                indA ++;
            } else {
                resultOfB.append("1");
                indB ++;
            }
            total ++;
        }
        while (indA + 1 <= n / 2){
            resultOfA.append("1");
            indA ++;
        }
        while (indB + 1 <= n / 2){
            resultOfB.append("1");
            indB ++;
        }

        while (indA < n){
            resultOfA.append("0");
            indA ++;
        }
        while (indB < n){
            resultOfB.append("0");
            indB ++;
        }
        out.append(resultOfA);
        out.append("\n");
        out.append(resultOfB);

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static long nextLong(){
        return Long.parseLong(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}


import java.util.*;
import java.io.*;
public class Main {
    static BufferedReader reader
		= new BufferedReader(new InputStreamReader(System.in));
    static StringBuilder out = new StringBuilder();

    public static void main(String[] args){
        // A player may go to final iff
        // One or two of the followings hold
        // 1) the rank in its semifinal is better than or equal to n/2
        // 2) the rank in total is better than or equal to n
        int n = nextInt();
        StringBuilder resultOfA = new StringBuilder();
        StringBuilder resultOfB = new StringBuilder();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; i++){
            int[] inp = nextIntArray();
            a[i] = inp[0];
            b[i] = inp[1];
        }
        int indA = 0;
        int indB = 0;
        int total = 0; // how many players we have seen so far
        while (total + 1 <= n){
            if (a[indA] < b[indB]){
                resultOfA.append("1");
                indA ++;
            } else {
                resultOfB.append("1");
                indB ++;
            }
            total ++;
        }
        while (indA + 1 <= n / 2){
            resultOfA.append("1");
            indA ++;
        }
        while (indB + 1 <= n / 2){ resultOfB.append("1");
            indB ++;
        }

        while (indA < n){
            resultOfA.append("0");
            indA ++;
        }
        while (indB < n){
            resultOfB.append("0");
            indB ++;
        }
        out.append(resultOfA);
        out.append("\n");
        out.append(resultOfB);

        System.out.println(out);
    }

    // the followings are methods to take care of inputs.
    static int nextInt(){
        return Integer.parseInt(nextLine());
    }
    static long nextLong(){
        return Long.parseLong(nextLine());
    }
    static int[] nextIntArray(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length]; for (int i = 0; i < ary.length; i++){
            ary[i] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static int[] nextIntArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        int[] ary = new int[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Integer.parseInt(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArray(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length];
        for (int i = 0; i < inp.length; i++){
            ary[i] = Long.parseLong(inp[i]);
        }
        return ary;
    }
    static long[] nextLongArrayFrom1(){
        String[] inp = nextLine().split("\\s+");
        long[] ary = new long[inp.length + 1];
        for (int i = 0; i < inp.length; i++){
            ary[i+1] = Long.parseLong(inp[i]);
        }
        return ary;
    }
	static String nextLine(){
		try {
			return reader.readLine().trim();
		} catch (Exception e){}
		return null;
	}
}


import java.io.*;
import java.util.*;

public class B
{
    public static void main(String[] args) throws IOException
    {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = Integer.parseInt(in.readLine());
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[2*n];
        int[] d = new int[2*n];
        HashMap<Integer,Integer> m = new HashMap<Integer,Integer>();
        for (int i = 0; i < n; i++)
        {
        	StringTokenizer st = new StringTokenizer(in.readLine());
        	int x = Integer.parseInt(st.nextToken());
        	int y = Integer.parseInt(st.nextToken());
        	m.put(x, i);
        	m.put(y, n+i);
        	a[i] = x;
        	b[i] = y;
        	c[i] = x;
        	c[i+n] = y;
        }
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        for (int i = 0; i < n/2; i++)
        {
        	d[m.get(a[i])] = 1;
        	d[m.get(b[i])] = 1;
        }
        for (int i = 0; i < n; i++)
        {
        	d[m.get(c[i])] = 1;
        }
        for (int i = 0; i < n; i++)
        {
        	out.print(d[i]);
        }
        out.println();
        for (int i = 0; i < n; i++)
        {
        	out.print(d[i+n]);
        }
        out.println();
        out.close();
        System.exit(0);
    }
}


import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Scanner;

/**
 * http://codeforces.com/contest/378/problem/B
 */
public class B {

	public static void main(String[] args) throws IOException, ParseException {
		new B().doJob();
	}

	private void doJob() throws ParseException, IOException {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Time[] times = new Time[n * 2];
			long[] firstSem = new long[n];
			long[] secSem = new long[n];
			for (int i = 0; i < n; i++) {
				long firstRes = scanner.nextLong();
				firstSem[i] = firstRes;
				long secondRes = scanner.nextLong();
				secSem[i] = secondRes;
				times[i * 2] = new Time(i, firstRes, 1);
				times[i * 2 + 1] = new Time(i, secondRes, 2);
			}
			Arrays.sort(times);
			int[] resFirst = new int[n];
			int[] resSecond = new int[n];
			int finals = n / 2;
			for (int i = 0; i < finals; i++) {
				resFirst[i] = 1;
				resSecond[i] = 1;
			}
			for (int i = 0; i < n; i++) {
				int id = times[i].getId();
				if (times[i].getDiv() == 1) {
					resFirst[id] = 1;
				} else {
					resSecond[id] = 1;
				}
			}
			System.out.println(convertToString(resFirst));
			System.out.println(convertToString(resSecond));
		}
	}

	private String convertToString(int array[]) {
		StringBuilder res = new StringBuilder();
		for (int i = 0; i < array.length; i++) {
			res.append(array[i]);
		}
		return res.toString();
	}

	private static class Time implements Comparable<Time> {
		private final long time;
		private final int id;
		private final int div;

		public Time(int id, long time, int div) {
			this.id = id;
			this.time = time;
			this.div = div;
		}

		public long getTime() {
			return time;
		}

		public int getId() {
			return id;
		}

		public int getDiv() {
			return div;
		}

		@Override
		public int compareTo(Time o) {
			return (int) (time - o.time);
		}

	}

}


import java.io.IOException;
import java.text.ParseException;
import java.util.Arrays;
import java.util.Scanner;

/**
 * http://codeforces.com/contest/378/problem/B
 */
public class B {

	public static void main(String[] args) throws IOException, ParseException {
		new B().doJob();
	}

	private void doJob() throws ParseException, IOException {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			Time[] times = new Time[n * 2];
			long[] firstSem = new long[n];
			long[] secSem = new long[n];
			for (int i = 0; i < n; i++) {
				long firstRes = scanner.nextLong();
				firstSem[i] = firstRes;
				long secondRes = scanner.nextLong();
				secSem[i] = secondRes;
				times[i * 2] = new Time(i, firstRes, 1);
				times[i * 2 + 1] = new Time(i, secondRes, 2);
			}
			Arrays.sort(times);
			int[] resFirst = new int[n];
			int[] resSecond = new int[n];
			int finals = n / 2;
			for (int k = 0; k <= finals; k++) {
				int leftByTime = n - 2 * k;
				for (int i = 0; i < k; i++) {
					resFirst[i] = 1;
					resSecond[i] = 1;
				}
				int count = 0;
				for (int i = 0; i < times.length && count < leftByTime; i++) {
					int id = times[i].getId();
					if (id != k - 1) {
						count++;
						if (times[i].getDiv() == 1) {
							resFirst[id] = 1;
						} else {
							resSecond[id] = 1;
						}
					}
				}
			}
			System.out.println(converToString(resFirst));
			System.out.println(converToString(resSecond));
		}
	}

	private String converToString(int array[]) {
		StringBuilder res = new StringBuilder();
		for (int i = 0; i < array.length; i++) {
			res.append(array[i]);
		}
		return res.toString();
	}

	private static class Time implements Comparable<Time> {
		private final long time;
		private final int id;
		private final int div;

		public Time(int id, long time, int div) {
			this.id = id;
			this.time = time;
			this.div = div;
		}

		public long getTime() {
			return time;
		}

		public int getId() {
			return id;
		}

		public int getDiv() {
			return div;
		}

		@Override
		public int compareTo(Time o) {
			return (int) (time - o.time);
		}

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class C371B {

	public static void main(String[] args) throws IOException {

		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(bf.readLine().trim());
		int[][] a = new int[n + 1][2];
		String s[];
		for (int i = 1; i <= n; i++) {
			s = bf.readLine().trim().split(" ");
			a[i][0] = Integer.parseInt(s[0]);
			a[i][1] = Integer.parseInt(s[1]);
		}
		int left = 1, right = 1;
		for (int i = 1; i <= n; i++) {
			if (a[left][0] > a[right][1]) right++;
			else left++;
		}
		for (int i = 1; i <= n; i++) {
			if (i * 2 <= n || left - 1 >= i) System.out.print("1");
			else System.out.print("0");
		}
		System.out.println();
		for (int i = 1; i <= n; i++) {
			if (i * 2 <= n || right - 1 >= i) System.out.print("1");
			else System.out.print("0");
		}

	}

}


import java.io.PrintStream;
import java.util.*;

public class Problem222B {
    public static void main(String[] args) {
        new Problem222B(new Scanner(System.in), System.out).solve();
    }

    private Scanner in;
    private PrintStream out;

    public Problem222B(Scanner in, PrintStream out) {
        this.out = out;
        this.in = in;
    }

    public void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] ab = new int[n*2];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            ab[i*2] = a[i];
            b[i] = in.nextInt();
            ab[i*2 + 1] = b[i];
        }

        Arrays.sort(ab);

        int cut = ab[n - 1];

        int i;
        for (i = 0; i < n/2; i++) {
            out.print(1);
        }
        while (i < n && a[i] <= cut) {
            out.print(1);
            i++;
        }
        for (; i < n; i++) {
            out.print(0);
        }
        out.println();

        for (i = 0; i < n/2; i++) {
            out.print(1);
        }
        while (i < n && b[i] <= cut) {
            out.print(1);
            i++;
        }
        for (; i < n; i++) {
            out.print(0);
        }
        out.println();
    }
}


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

ll binpow(ll a, ll n, ll p) {
    ll res = 1;
    while(n) {
        if (n & 1)
            res = (res * a) % p;
        a = (a * a) % p;
        n >>= 1;
    }
    return res;
}

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll t, n, a, k, d;
    cin >> t;
    vector <int> v, used;
    while(t--) {
        cin >> n >> k >> d;
        v.resize(n);
        used.resize(k);
        for (int i = 0; i < n; ++i) {
            cin >> v[i];
            v[i]--;
        }
        ll ma = 1e9, c = 0;
        for (int i = 0; i < d; ++i) {
            if (!used[v[i]])
                c++;
            used[v[i]]++;
        }
        ma = min(ma, c);
        for (int i = d; i < n; ++i) {
            if (used[v[i - d]] == 1) {
                c--;
            }
            used[v[i - d]]--;
            if (used[v[i]] == 0) {
                c++;
            }

            used[v[i]]++;
            ma = min(ma, c);
        }
        printf("%d\n", ma);
        //cout << ma  << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        map<ll, ll> ison, arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;

            }
            if(i>=d-1)ans=min(ans, cur);
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        vector<ll> ison(k+1, 0), arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;
                ans=min(ans, cur);
            }
        }
        cout << min(ans, cur) << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        vector<ll> ison(k+1, 0), arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;

            }
            if(i>=d-1 && i<n)ans=min(ans, cur);
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        vector<ll> ison(k, 0), arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;
                ans=min(ans, cur);
            }
        }
        cout << min(ans, cur) << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        map<ll, ll> ison; vector<ll> arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;

            }
            if(i>=d-1)ans=min(ans, cur);
        }
        cout << ans << endl;
    }
}


#include <bits/stdc++.h>
#define loop(i, a, b) for(int i=a;i<b;i++)
#define mn 500100
#define to first
#define co second

using namespace std;

typedef long long ll;

int main() {
    ll t; cin >> t;
    loop(asidhj, 0, t){
        ll n, k, d, cur=0;cin >> n >> k >> d;
        ll ans=k;
        vector<ll> ison(k+1, 0), arr(n, 0);
        loop(i, 0,n) scanf("%lld", &arr[i]), arr[i]--;
        loop(i, 0, n){
            if(ison[arr[i]]==0) cur++;ison[arr[i]]++;
            if (i>=d){
                ison[arr[i-d]]--;
                if(ison[arr[i-d]]==0) cur--;

            }
            if(i>=d-1)ans=min(ans, cur);
        }
        cout << ans << endl;
    }
}


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

int main(int argc, char const *argv[]) {
    int t;
    scanf("%d", &t);
    for (int z = 0; z < t; z++){
        int n,k,d,j=0,x,q = 0;
        bool vf = false;
        scanf("%d %d %d", &n, &k, &d);
        int a = n;
        int *v = (int *)calloc(k,sizeof(int));
        int *aux = (int *)malloc(d*sizeof(int));
        for (int i = 0; i < n; i++){
            scanf("%d", &x);
            v[x-1]++;
            if (vf) {
                v[aux[j]-1]--;
                if (v[aux[j]-1] == 0) q--;
            }
            if (vf && aux[j] == x && v[x-1] == 1) q--;
            aux[j]=x;
            if (v[x-1] == 1) q++;
            if (j+1 == d) vf = true;
            if (vf) a = min(a,q);
            j = (j+1)%d;
        }
        free(v);
        free(aux);
        printf("%d\n", a);
    }
    return 0;
}


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

int main(int argc, char const *argv[]) {
    int t;
    scanf("%d", &t);
    for (int z = 0; z < t; z++){
        int n,k,d,j=0,x,q = 0;
        bool vf = false;
        scanf("%d %d %d", &n, &k, &d);
        int a = n;
        int *v = (int *)calloc(k,sizeof(int));
        int *aux = (int *)malloc(d*sizeof(int));
        for (int i = 0; i < n; i++){
            scanf("%d", &x);
            v[x-1]++;
            if (vf) {
                v[aux[j]-1]--;
                if (v[aux[j]-1] == 0) q--;
            }
            if (vf && aux[j] == x && v[x-1] == 1) q--;
            aux[j]=x;
            if (v[x-1] == 1) q++;
            if (j+1 == d) vf = true;
            if (vf) a = min(a,q);
            j = (j+1)%d;
        }
        printf("%d\n", a);
    }
    return 0;
}


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

int main(int argc, char const *argv[]) {
  int t;
  cin >> t;
  for (int z = 0; z < t; z++){
    int n,k,d,j=0,x;
    bool vf = false;
    cin >> n >> k >> d;
    int a = n;
    int *v = (int *)malloc(d*sizeof(int));
    for (int i = 0; i < n; i++){
      cin >> x;
      v[j] = x;
      if (j+1 == d) vf = true;
      if (vf && a != 1){
        set<int> s;
        for (int k = 0; k < d && (int)s.size() < a; k++) {
          s.insert(v[k]);
        }
        a = min((int)s.size(),a);
      }
      j = (j+1)%d;
    }
    cout << a << endl;
  }
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int t;
  scanf("%d", &t);
  for (int z = 0; z < t; z++){
    int n,k,d,j=0,x;
    bool vf = false;
    scanf("%d %d %d", &n, &k, &d);
    int a = n;
    int *v = (int *)malloc(d*sizeof(int));
    for (int i = 0; i < n; i++){
      scanf("%d", &x);
      v[j] = x;
      if (j+1 == d) vf = true;
      if (vf && a != 1){
        set<int> s;
        for (int k = 0; k < d && (int)s.size() < a; k++) {
          s.insert(v[k]);
        }
        a = min((int)s.size(),a);
      }
      j = (j+1)%d;
    }
    printf("%d\n", a;
  }
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int t;
  scanf("%d", &t);
  for (int z = 0; z < t; z++){
    int n,k,d,j=0,x,q = 0;
    bool vf = false;
    scanf("%d %d %d", &n, &k, &d);
    int a = n;
    int *v = (int *)calloc(k,sizeof(int));
			int *aux = (int *)malloc(d*sizeof(int));
    for (int i = 0; i < n; i++){
      scanf("%d", &x);
      v[x-1]++;
				if (vf) {
					v[aux[j]-1]--;
					if (v[aux[j]-1] == 0) q--;
				}
				aux[j]=x;
				if (v[x-1] == 1) q++;
      if (j+1 == d) vf = true;
      if (vf){
  				a = min(a,q);
 				}
				j = (j+1)%d;
    }
    printf("%d\n", a);
  }
  return 0;
}


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

int main(int argc, char const *argv[]) {
  int t;
  cin >> t;
  for (int z = 0; z < t; z++){
    int n,k,d,j=0,x;
    bool vf = false;
    cin >> n >> k >> d;
    int a = n;
    int *v = (int *)malloc(d*sizeof(int));
    for (int i = 0; i < n; i++){
      cin >> x;
      v[j] = x;
      if (j+1 == d) vf = true;
      if (vf && a != 1){
        set<int> s;
        for (int k = 0; k < d; k++) s.insert(v[k]);
        a = min((int)s.size(),a);
      }
      j = (j+1)%d;
    }
    cout << a << endl;
  }
  return 0;
}


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

    int main(int argc, char const *argv[]) {
      int t;
      scanf("%d", &t);
      for (int z = 0; z < t; z++){
        int n,k,d,j=0,x;
        bool vf = false;
        scanf("%d %d %d", &n, &k, &d);
        int a = n;
        int *v = (int *)malloc(d*sizeof(int));
        for (int i = 0; i < n; i++){
          scanf("%d", &x);
          v[j] = x;
          if (j+1 == d) vf = true;
          if (vf && a != 1){
            set<int> s;
            for (int k = 0; k < d && (int)s.size() < a; k++) {
              s.insert(v[k]);
            }
            a = min((int)s.size(),a);
          }
          j = (j+1)%d;
        }
        printf("%d\n", a);
      }
      return 0;
    }


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;

void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    int val[k+1]={0};
    int a[n];
    forn(i,n){
        cin>>a[i];
    }
    int sum=0;
    forn(i,d){
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
    }
    int ans=sum;
    forse(i,d,n){
        val[a[i-d]]--;
        val[a[i]]++;
        if(val[a[i-d]]==0){sum--;}
        if(val[a[i]]==1){sum++;}
        ans=min(ans,sum);
    }
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;
int val[1e6+1];
void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    memset(val,0,sizeof(val));
    int a[n];
    int ans=k;
    int sum=0;
    forn(i,n){
        cin>>a[i];
        if(i<d){
            val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        } else {
            ans=min(ans,sum);
            val[a[i-d]]--;
        if(val[a[i-d]]==0){sum--;}
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        }
    }
    ans=min(ans,sum);
    if(d==1){cout<<1<<'\n'; return;}
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;

void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    int val[k+1]={0};
    int a[n];
    int ans=k;
    int sum=0;
    forn(i,n){
        cin>>a[i];
        if(i<d){
            val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        } else {
            ans=min(ans,sum);
            val[a[i-d]]--;
        if(val[a[i-d]]==0){sum--;}
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        }
    }
    ans=min(ans,sum);
    if(d==1){cout<<1<<'\n'; return;}
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;

void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    int val[k+1]={0};
    int a[n];
    forn(i,n){
        cin>>a[i];
    }
    if(d==1){cout<<1<<'\n'; return;}
    int sum=0;
    forn(i,d){
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
    }
    //cout<<sum<<'\n';
    int ans=sum;
    forse(i,d,n){
        val[a[i-d]]--;
        if(val[a[i-d]]==0){sum--;}
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        ans=min(ans,sum);
        if(ans==1){break;}
       // cout<<sum<<'\n';
    }
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;
int val[1000005];
void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    memset(val,0,sizeof(val));
    int a[n];
    int ans=k;
    int sum=0;
    forn(i,n){
        cin>>a[i];
        if(i<d){
            val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        } else {
            ans=min(ans,sum);
            val[a[i-d]]--;
        if(val[a[i-d]]==0){sum--;}
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        }
    }
    ans=min(ans,sum);
    if(d==1){cout<<1<<'\n'; return;}
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*Author - Dhananjay Singh (@Dhananjay_049)*/
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef vector<ll> vl;		typedef vector<int> vi;
typedef vector<vl> vvl;	  	typedef vector<vi> vvi;
typedef pair<ll, ll> pll;	typedef pair<int, int> pii;
#define forn(i,n) for(int i=0;i<n;i++)
#define rforn(i,n) for(int i=n-1;i>=0;i--)
#define forne(i,n) for(int i=1;i<=n;i++)
#define forse(i,s,e) for(int i=s;i<e;i++)
#define rforse(i,s,e) for(int i=e-1;i>=s;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define MOD 1000000007
#define F first
#define S second
#define pb push_back
#define fill(a,x) memset(a,x,sizeof a);
#define trav(a,x) for(auto &a:x)
#define INF	ll(1e18)
#ifdef DHANANJAY_049
#include "../code-pieces/trace.h"
#else
#define trace(args...)
#endif
//ordered_set T; T.insert(val);*T.find_by_order(index);T.order_of_key(val);
//find_by_order(k): It returns to an iterator to the kth element (counting from zero)
//order_of_key(k) : It returns to the number of items that are strictly smaller than our item k
//Thus we can now solve the above problem easily i.e. count of elements between l and r can be found by:
//o_set.order_of_key(r+1) – o_set.order_of_key(l)
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);}
void graph(vvi &adj, int m) {int x, y; forn(i, m) {cin >> x >> y; adj[x - 1].pb(y - 1); adj[y - 1].pb(x - 1);}}
 struct hash_pair {
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
const int mxN = 2e5 + 5;

void solve(){
    int n,k,d;
    cin>>n>>k>>d;
    int val[k+1]={0};
    int a[n];
    forn(i,n){
        cin>>a[i];
    }
    int sum=0;
    forn(i,d){
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
    }
    //cout<<sum<<'\n';
    int ans=sum;
    forse(i,d,n){
        val[a[i-d]]--;
        if(val[a[i-d]]==0){sum--;}
        val[a[i]]++;
        if(val[a[i]]==1){sum++;}
        ans=min(ans,sum);
       // cout<<sum<<'\n';
    }
    cout<<ans<<'\n';

}
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifdef DHANANJAY_049
	freopen("inp.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	freopen("err.txt", "w", stderr);
#endif
	int t = 1;
	cin >> t;
	while (t--) {
        solve();
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[1000005];

int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t --){
		int n,k,d;
		cin >> n >> k >> d;
		for(int i = 0; i <= k ;i ++) q[i] = 0;
		for(int i = 0; i < n; i ++){
			cin >> a[i];
		}
		int cnt = 0;

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		cout << ans << endl;
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[1000005];

int main()
{
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t --){
		int n,k,d;
		cin >> n >> k >> d;
		memset(q, 0, k*sizeof(int));
		for(int i = 0; i < n; i ++){
			cin >> a[i];
		}
		int cnt = 0;

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		cout << ans << endl;
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[100005],q[100005];

int main()
{
	int t;
	cin >> t;
	while(t --){
		memset(q, 0 , sizeof q);
		int n,k,d;

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

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		cout << ans << endl;
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[1000005];

int main()
{
	int t;
	scanf("%d",&t);
	while(t --){
		int n,k,d;
		scanf("%d%d%d",&n,&k,&d);
		memset(q, 0, k*sizeof(int));
		for(int i = 0; i < n; i ++){
			scanf("%d",&a[i]);
		}
		int cnt = 0;

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		printf("%d\n",ans);
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[200005];

int main()
{
	int t;
	cin >> t;
	while(t --){
		memset(q, 0 , sizeof q);
		int n,k,d;

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

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		cout << ans << endl;
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[1000005];

int main()
{
	int t;
	scanf("%d",&t);
	while(t --){
		int n,k,d;
		scanf("%d%d%d",&n,&k,&d);
		memset(q, 0,(k + 1)*sizeof(int));
		for(int i = 0; i < n; i ++){
			scanf("%d",&a[i]);
		}
		int cnt = 0;

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		printf("%d\n",ans);
	}
}


/*#include <iostream>
#include <cstring>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N = 2e4 + 5;
struct node{
	int to, next,w;
}edge[N << 1];
int head[N],w[N], d[N],s[N],sum[3];
int cnt = 0,Ans,pos,ans;
int n,m;
void add(int from, int to,int w){
	edge[cnt].to = to;
	edge[cnt].next = head[from];
	edge[cnt].w = w;
	head[from] = cnt ++;
}
void dfs_find(int S,int x,int fa){
	s[x] = 1;
	int max_part = 0;
	for(int i = head[x]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if( w[y] || y == fa) continue;
		dfs_find(S, y,x);
		s[x] += s[y];
		max_part = max(max_part , s[y]);
	}
	max_part = max(max_part, S - s[x]);
	if(max_part < ans){
		ans = max_part;
		pos = x;
	}
}
void dfs(int x, int fa){
	for(int i = head[x] ; ~i; i = edge[i].next){
		int y = edge[i].to;
		int z = edge[i].w;
		if(w[y] || y == fa) continue;
		d[y] = d[x] + z;
		d[y] %= 3;
		sum[d[y]] ++;
		dfs(y,x);
	}
}
void work(int S, int x){
	ans = S;
	dfs_find(S, x,-1);
	memset(d, 0, sizeof d);
	memset(sum, 0 , sizeof sum);
	w[pos] = 1;
	sum[0] ++;
	d[pos] = 0;
	dfs(pos, -1);
	Ans += sum[0]*sum[0] + sum[1]*sum[2]*2;

	int now = pos;
	for(int i = head[now]; ~i ; i = edge[i].next){
		int y = edge[i].to;
		if(w[y]) continue;
		memset(sum, 0 , sizeof sum);
		d[y] = edge[i].w%3;
		sum[d[y]] ++;
		dfs(y, -1);
		Ans = Ans - sum[0]*sum[0] - sum[1]*sum[2]*2;
		work(s[y], y);
	}
}
int main()
{

	int n;
	scanf("%d",&n);
	memset(head, -1, sizeof head);
	for(int i = 0 ; i < n - 1 ;i ++){
		int x, y, z;
		scanf("%d%d%d",&x,&y,&z);
		add(x , y , z);
		add(y , x , z);
	}

	memset(w, 0 , sizeof w);
	Ans = 0;
	work(n, 1);
	int g = __gcd(Ans, n*n);
	printf("%d/%d",Ans/g,n*n/g);

}
*/
#include <bits/stdc++.h>
using namespace std;
int a[200005],q[2000005];

int main()
{
	int t;
	cin >> t;
	while(t --){
		memset(q, 0 , sizeof q);
		int n,k,d;

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

		for(int i = 0; i < d; i ++){
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
		}

		int ans = 0;
		ans = cnt ;

		for(int i = d; i < n; i ++){
			q[a[i - d]] --;
			if(!q[a[i - d]]){
				cnt --;
			}
			if(!q[a[i]]){
				cnt ++;
			}
			q[a[i]] ++;
			ans = min(ans , cnt );
		}
		cout << ans << endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;

int main()
{
    IOS
    int q;cin>>q;
	map <int,int> m;
	set <int> s;
	while(q--){
		int n,k,d;
		cin>>n>>k>>d;
		int arr[n];
		m.clear();s.clear();
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;

		ll c[k]={0};
		forn(i,d){
			s.insert(arr[i]);
			m[arr[i]]++;
		}
		int ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(m[arr[pre]]==1)
				s.erase(arr[pre]);
			m[arr[pre]]--;
			pre++;
			s.insert(arr[j]);
			m[arr[j]]++;
			ans = min(ans,(ll)s.size());
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;

int main()
{
    IOS
    int q;cin>>q;
	map <int,int> m;
	set <int> s;
	while(q--){
		int n,k,d;
		cin>>n>>k>>d;
		int arr[n];
		m.clear();s.clear();
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;

		forn(i,d){
			s.insert(arr[i]);
			m[arr[i]]++;
		}
		int ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(m[arr[pre]]==1)
				s.erase(arr[pre]);
			m[arr[pre]]--;
			pre++;
			s.insert(arr[j]);
			m[arr[j]]++;
			ans = min(ans,(int)s.size());
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;

int main()
{
    IOS
    int q;cin>>q;
	map <ll,ll> m;
	while(q--){
		ll n,k,d;
		cin>>n>>k>>d;
		ll arr[n];
		m.clear();
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;
		set <ll> s;
		ll c[k]={0};
		forn(i,d){
			s.insert(arr[i]);
			m[arr[i]]++;
		}
		ll ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(m[arr[pre]]==1)
			{
				s.erase(arr[pre]);
			}
			m[arr[pre]]--;
			pre++;
			if(m.find(arr[j]) != m.end() && m[arr[j]]>=1);
			else s.insert(arr[j]);
			m[arr[j]]++;
			ans = min(ans,(ll)s.size());
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;

int main()
{
    IOS
    int q;cin>>q;
	map <int,int> m;
	set <int> s;
	while(q--){
		int n,k,d;
		cin>>n>>k>>d;
		int arr[n];
		m.clear();s.clear();
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;

		ll c[k]={0};
		forn(i,d){
			s.insert(arr[i]);
			m[arr[i]]++;
		}
		int ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(m[arr[pre]]==1)
				s.erase(arr[pre]);
			m[arr[pre]]--;
			pre++;
			s.insert(arr[j]);
			m[arr[j]]++;
			ans = min(ans,(int)s.size());
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;

int main()
{
    IOS
    int q;cin>>q;
	map <ll> m;
	while(q--){
		ll n,k,d;
		cin>>n>>k>>d;
		ll arr[n];
		m.clear();
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;
		set <ll> s;
		ll c[k]={0};
		forn(i,d){
			s.insert(arr[i]);
			m[arr[i]]++;
		}
		ll ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(m[arr[pre]]==1)
			{
				s.erase(arr[pre]);
			}
			m[arr[pre]]--;
			pre++;
			if(m.find(arr[j]) != m.end() && m[arr[j]]>=1);
			else s.insert(arr[j]);
			m[arr[j]]++;
			ans = min(ans,(ll)s.size());
		}
		cout<<ans<<endl;
	}
}


#include <iostream>
#include <bits/stdc++.h>
#define forn(i,n)for(int i=0;i<n;i++)
#define forna(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1e9+7
#define ff first
#define ss second
#define INF 1e9
#define MAX 100000
#define ya cout<<"YES"<<endl;continue;
typedef long long ll;
using namespace std;
;

int main()
{
    IOS
    int q;cin>>q;
	while(q--){
		ll n,k,d;
		cin>>n>>k>>d;
		ll arr[n];
		forn(i,n) cin>>arr[i];
		forn(i,n) arr[i]--;
		set <ll> s;
		ll c[k]={0};
		forn(i,d){
			s.insert(arr[i]);
			c[arr[i]]++;
		}
		ll ans = s.size();
		int pre=0;
		forna(j,d,n){
			if(c[arr[pre]]==1)
			{
				s.erase(arr[pre]);
			}
			c[arr[pre]]--;
			pre++;
			if(c[arr[j]]==0) s.insert(arr[j]);
			c[arr[j]]++;
			ans = min(ans,(ll)s.size());
		}
		cout<<ans<<endl;
	}
}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=100000000000,j=0,count=0;
		ll a[n];
		ll temp[200001]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}
		}

			ans=min(ans,count);
		for(ll i=d;i<n;i++)
		{

				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;

				}
				else if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

				temp[a[j]]--;
				temp[a[i]]++;
				j++;
				ans=min(ans,count);

		}

		cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}

			if(i>=d)
			{

					ans=min(ans,count);
				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;

				}
				else if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

				temp[a[j]]--;
				temp[a[i]]++;
				j++;
				ans=min(ans,count);

			}

		}
		ans=min(ans,count);

		cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}
			else
			{

					ans=min(ans,count);
				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;

				}
				else if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

				temp[a[j]]--;
				temp[a[i]]++;
				j++;
				ans=min(ans,count);

			}

		}
		ans=min(ans,count);

		cout<<ans<<endl;

	}
return 0;
}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=1000,j=0,count=0;
		ll a[n];
		ll temp[200001]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}
		}

			ans=min(ans,count);
		for(ll i=d;i<n;i++)
		{

				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;
					temp[a[i]]--;

				}
				else
				{	if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

					temp[a[i]]++;
				}

				j++;
				ans=min(ans,count);

		}

		cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}

			else
			{

				ans=min(ans,count);
				temp[a[j]]--;
				if(temp[a[j]]==0&&a[j]!=a[i]&&temp[a[i]]!=0)
				count--;
				if(temp[a[j]]!=0&&a[j]!=a[i] &&temp[a[i]]==0)
				count++;

				 temp[a[i]]++;
				 j++;
					ans=min(ans,count);
			}

		}
		ans=min(ans,count);

		cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		map<ll,ll>m;
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];

			if(i<d){
					m[a[i]]++;
				 count=m.size();
			}

			else
			{

			ans=min(ans,count);
				m[a[j]]--;
				if(m[a[j]]==0)
				{
				count--;
				}
				m[a[i]]++;
				if(m[a[i]]==1)count++;
				j++;

				ans=min(ans,count);
			}

	}

		ans=min(ans,count);
	cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}
		}

			ans=min(ans,count);
		for(ll i=d;i<n;i++)
		{

				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;

				}
				else if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

				temp[a[j]]--;
				temp[a[i]]++;
				j++;
				ans=min(ans,count);

		}

		cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		map<ll,ll>m;
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];

			if(i<d){
					m[a[i]]++;
				 count=m.size();
			}

			else
			{

			ans=min(ans,count);
				m[a[j]]--;
				if(m[a[j]]==0)
				{
				count--;
				}
				m[a[i]]++;
				if(m[a[i]]==1)count++;
				j++;

				ans=min(ans,count);
			}

	}
	ll x=m.size();
		ans=min(ans,x);
	cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		map<ll,ll>m;
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];

			if(i<d){
					m[a[i]]++;
				 count=m.size();
			}

	}

		ans=min(ans,count);

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

				ans=min(ans,count);
		}
	cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=k+1,j=0,count=0;
		ll a[n];
		map<ll,ll>m;
		ll temp[k+1]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];

			if(i<d)
			m[a[i]]++;
			else
			{
			ll x=m.size();
			ans=min(ans,x);
				m[a[j]]--;
				if(m[a[j]]==0)
				{
					m.erase(a[j]);
				}
				m[a[i]]++;
				j++;
				x=m.size();
				ans=min(ans,x);
			}

	}
	ll x=m.size();
		ans=min(ans,x);
	cout<<ans<<endl;

	}

}


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

int main()
{
	ll t;cin>>t;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
			ll ans=1000,j=0,count=0;
		ll a[n];
		ll temp[200001]={0};
		for(ll i=0;i<n;i++){
			cin>>a[i];
			if(i<d){
				if(temp[a[i]]==0)
				count++;

			temp[a[i]]++;}
		}

			ans=min(ans,count);
		for(ll i=d;i<n;i++)
		{

				if(temp[a[i]]!=0&&temp[a[j]]==1&&a[i]!=a[j])
				{
					count--;

				}
				else
				{	if(temp[a[i]]==0&&temp[a[j]]>1)
					count++;

				}
				temp[a[j]]--;
	temp[a[i]]++;
				j++;
				ans=min(ans,count);

		}

		cout<<ans<<endl;

	}

}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		// vector <bool> check(1000005,false);
		vector <ll> count(1000005,0);
		ll sum=0,lsum;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
			if(i==d-1)
			{
				lsum=sum;
			}
			if(i>=d)
			{
				ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			}
		}
		cout<<sum<<"\n";
		/*ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";*/
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	vector <ll> count(1000005,0);
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		// vector <bool> check(1000005,false);
		memset(&count,0,sizeof(count));
		ll sum=0,lsum;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
			if(i==d-1)
			{
				lsum=sum;
			}
			if(i>=d)
			{
				ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			}
		}
		cout<<sum<<"\n";
		/*ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";*/
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	vector <ll> count(1000005,0);
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		// vector <bool> check(1000005,false);
		// memset(&count,0,sizeof(count));
		ll sum=0,lsum;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			count[temp]=0;
		}
		for(ll i=0;i<n;i++)
		{
			ll temp=arr[i];
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
			if(i==d-1)
			{
				lsum=sum;
			}
			if(i>=d)
			{
				ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			}
		}
		cout<<sum<<"\n";
		/*ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";*/
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	// cin>>t;
	t=1;
	// vector <ll> count(1000005,0);
	while(t--)
	{
		ll n;
		cin>>n;
		double k;
		cin>>k;
		vector <ll> arr;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
		}
		ll ans=0;
		if(k==1)
		{
			cout<<n*(n-1)/2<<"\n";
			continue;
		}
		for(ll i=0;i<n;i++)
		{
			for(ll j=i+1;j<n;j++)
			{
				ll temp=arr[i]*arr[j];

				if(temp==1)
				{
					// cout<<i<<" "<<j<<endl;
					ans++;
					continue;
				}
				// double a1=log(temp)/(log(k)*k);

				// a1=a1/k;
				// double a=
				double x=pow(k,double(log(temp)/(log(k)*k)));
				/*if(i==2 && j==4)
				{
					cout<<int(x)<<" "<<x<<"Harsh";
					double a3=floor(x);
					cout<<setprecision(20)<<x<<endl;
					cout<<setprecision(20)<<a3<<endl;
					/*if(a3-x<=0.0000000005)
					{
						cout<<a3-x<<" Okay";
						cout<<"Game";
						cout<<int(x)<<" "<<x<<"Harsh";
					}
				}*/

				if(abs(int(x)-x)<=0.0000000005 && x>=1)
				{

					// cout<<i<<" "<<j<<"\n";
					ans++;
				}
			}
		}
		cout<<ans<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		vector <bool> check(1000005,false);
		vector <ll> count(1000005,0);
		ll sum=0;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
		}
		// cout<<sum<<"\n";
		ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		vector <bool> check(1000005,false);
		vector <ll> count(1000005,0);
		ll sum=0,lsum;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
			if(i==d-1)
			{
				lsum=sum;
			}
			if(i>=d)
			{
				ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			}
		}
		cout<<sum<<"\n";
		/*ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";*/
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define mod 1000000007
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	ll t;
	cin>>t;
	// t=1;
	vector <ll> count(1000005,0);
	while(t--)
	{
		ll n,k,d;
		cin>>n>>k>>d;
		vector <ll> arr;
		// vector <bool> check(1000005,false);
		memset(count,0,sizeof(count));
		ll sum=0,lsum;
		for(ll i=0;i<n;i++)
		{
			ll temp;
			cin>>temp;
			arr.push_back(temp);
			if(i<=d-1)
			{
				count[temp]++;
				if(count[temp]==1)
				{
					sum++;
				}
			}
			if(i==d-1)
			{
				lsum=sum;
			}
			if(i>=d)
			{
				ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			}
		}
		cout<<sum<<"\n";
		/*ll lsum=sum;
		for(ll i=d;i<n;i++)
		{
			ll psum=0;
			// cout<<i<<" "<<count[arr[i-d]]<<"\n";
			count[arr[i-d]]--;
			if(count[arr[i-d]]==0)
			{
				// cout<<"Hello";
				psum=lsum-1;
			}
			else
			{
				psum=lsum;
			}
			// cout<<psum<<" ";
			count[arr[i]]++;
			if(count[arr[i]]==1)
			{

				psum++;
			}
			if(psum<sum)
			{
				sum=psum;
			}
			lsum=psum;
			// cout<<psum<<"\n";
		}
		cout<<sum<<"\n";*/
	}
	return 0;
}


#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N=2e5+100;
int n,k,d;
int cnt[N],a[N];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int res=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]])res++;
            cnt[a[i]]++;
        }
        int ans=res;
        for(int i=d+1;i<=n;i++)
        {
            if(!cnt[a[i]])res++;
            cnt[a[i]]++;
            cnt[a[i-d]]--;
            if(!cnt[a[i-d]])res--;
            ans=min(ans,res);
        }
        printf("%d\n",ans);
        for(int i=1;i<=k;i++)cnt[i]=0;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;
const int maxn=2e5+5;
struct node
{
    int l,r;
    int v;
} T[maxn*40];
int cnt=0;
int a[maxn],past[1000100],root[maxn],b[maxn];
void update(int pos,int l,int r,int &cur,int pre,int val)
{
    cur=++cnt;
    T[cur]=T[pre];
    T[cur].v+=val;
    if(l==r)
        return;
    int mid=l+r>>1;
    if(pos<=mid)
        update(pos,l,mid,T[cur].l,T[pre].l,val);
    else
        update(pos,mid+1,r,T[cur].r,T[pre].r,val);
}
int query(int L,int R,int l,int r,int rt)
{
    if(L==l&&r==R)
        return T[rt].v;
    int mid=l+r>>1;
    if(R<=mid)
        return query(L,R,l,mid,T[rt].l);
    else if(L>=mid+1)
        return query(L,R,mid+1,r,T[rt].r);
    else
        return (query(L,mid,l,mid,T[rt].l)+query(mid+1,R,mid+1,r,T[rt].r));
}
int main()
{

    int n,_,k,d;
    scanf("%d",&_);
    while(_--)
    {
        scanf("%d%d%d",&n,&k,&d);
        for(int i=1; i<=n; i++)
            scanf("%d",&a[i]);
        cnt=0;
        for(int i=1; i<=n; i++)
        {
            if(past[a[i]])
            {
                update(past[a[i]],1,n,root[i],root[i-1],-1);
                update(i,1,n,root[i],root[i],1);
            }
            else
                update(i,1,n,root[i],root[i-1],1);
            past[a[i]]=i;
        }
        int ans=n;
        for(int i=1; i<=n-d+1; i++)

            ans=min(ans,query(i,i+d-1,1,n,root[i+d-1]));

        for(int i=1; i<=n; i++)
            past[a[i]]=0;
        printf("%d\n",ans);
    }
    return 0;
}