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

public class game_bm {
	FastScanner in;
	PrintWriter out;

	class FenwickTree {
		int[] s;
		int n;

		public FenwickTree(int n) {
			this.n = n;
			s = new int[n];
		}

		int get(int r) {
			int res = 0;
			for (; r >= 0; r = (r & (r + 1)) - 1) {
				res += s[r];
			}
			return res;
		}

		void clear() {
			Arrays.fill(s, 0);
		}

		void add(int pos, int val) {
			for (; pos < n; pos = pos | (pos + 1))
				s[pos] += val;
		}
	}

	void solve() {
		int tt = in.nextInt();
		for (int t = 0; t < tt; t++) {
			int n = in.nextInt();
			int m = in.nextInt();
			int k = in.nextInt();
			int[] a = new int[n];
			ArrayList<Integer>[] pos = new ArrayList[n];
			for (int i = 0; i < n; i++) {
				pos[i] = new ArrayList<>();
			}
			for (int i = 0; i < n; i++) {
				int val = in.nextInt() - 1;
				if (val >= 0 && val < n) {
					pos[val].add(i);
				}
			}
			int left = -1, right = n;
			FenwickTree ft = new FenwickTree(n);
			while (right - left > 1) {
				int mid = (left + right) >>> 1;
				ft.clear();
				boolean totalOk = true;
				for (int x = mid; x >= 0; x--) {
					boolean ok = false;
					for (int i = pos[x].size() - 1; i >= 0; i--) {
						int nowPos = pos[x].get(i);
						if (ft.get(nowPos) < k) {
							ok = true;
							ft.add(nowPos, 1);
							break;
						}
					}
					if (!ok) {
						totalOk = false;
						break;
					}
				}
				if (totalOk) {
					left = mid;
				} else {
					right = mid;
				}
			}
			out.println(left + 1);
		}
	}

	void run() {
		try {
			in = new FastScanner(new File("game.in"));
			out = new PrintWriter(new File("game.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

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

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

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

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

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