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

public class game_av_wa5 {

	FastScanner in;
	PrintWriter out;

	void solve() {
		int n = in.nextInt(), m = in.nextInt(), k = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt() - 1;
		}
		int left = 0, right = m + 1;

		while (left < right - 1) {
			int mid = (left + right) >> 1;
			if (max(filter(a, mid - 1), mid, k) == mid) {
				left = mid;
			} else {
				right = mid;
			}
		}

		out.println(left);
	}

	int max(int[] a, int m, int k) {
		TreeSet<Item> setByOcc = new TreeSet<>();
		TreeSet<Integer> setByValue = new TreeSet<>();
		int[] nextOccur = new int[a.length];
		int[] lastOcc = new int[m];
		Arrays.fill(lastOcc, a.length);
		for (int i = a.length - 1; i >= 0; i--) {
			nextOccur[i]  = lastOcc[a[i]];
			lastOcc[a[i]] = i;
		}
		
		int played = 0;
		for (int t = 0; t < a.length; t++) {
			int i = a[t];
			if (i < played) {
				lastOcc[i] = nextOccur[t];
				continue;
			}
			Item item = new Item(i, lastOcc[i]);
			if (setByOcc.contains(item)) {
				setByOcc.remove(item);
				lastOcc[i] = nextOccur[t];
				item.nextOcc = lastOcc[i];
				setByOcc.add(item);
				continue;
			}

			lastOcc[i] = nextOccur[t];
			setByOcc.add(new Item(i, lastOcc[i]));
			setByValue.add(i);

			while (setByValue.size() > 0 && setByValue.first() == played) {
				setByOcc.remove(new Item(played, lastOcc[played]));
				setByValue.pollFirst();
				played++;
			}

			if (setByOcc.size() == k) {
				Item rem = setByOcc.pollLast();
				setByValue.remove(rem.value);
			}
		}
		return played;
	}

	class Item implements Comparable<Item> {
		int value, nextOcc;

		public Item(int value, int nextOcc) {
			super();
			this.value = value;
			this.nextOcc = nextOcc;
		}

		@Override
		public int compareTo(Item o) {
			if (nextOcc != o.nextOcc) {
				return -Integer.compare(nextOcc, o.nextOcc);
			}
			return Integer.compare(value, o.value);
		}

		@Override
		public String toString() {
			return "Item [value=" + value + ", nextOcc=" + nextOcc + "]";
		}
	}

	int[] filter(int[] a, int max) {
		int size = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] <= max) {
				size++;
			}
		}
		int[] b = new int[size];
		int ptr = 0;
		for (int i = 0; i < a.length; i++) {
			if (a[i] <= max) {
				b[ptr++] = a[i];
			}
		}
		return b;
	}

	void run() {
		try {
			in = new FastScanner("game.in");
			out = new PrintWriter("game.out");
			int T = in.nextInt();
			while (T-- > 0) {
				solve();
			}
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(String s) {
			try {
				br = new BufferedReader(new FileReader(s));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String nextToken() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(nextToken());
		}

		long nextLong() {
			return Long.parseLong(nextToken());
		}

		double nextDouble() {
			return Double.parseDouble(nextToken());
		}
	}

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