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

public class game_av_wa {

	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 result = max(a, m , k);
		out.println(result);
	}
	
	int max(int[] a, int m, int k) {
		boolean[] have = new boolean[m];
		boolean[] need = new boolean[m];
		for (int i = 0; i < Math.min(k, m); i++) {
			need[i] = true;
		}
		
		int played = 0;
		for (int i : a) {
			if (need[i]) {
				have[i] = true;
				need[i] = false;
			}
			
			while (played < m && have[played]) {
				have[played] = false;
				if (played + k < m) {
					need[played + k] = true;
				}
				played++;
			}
		}
		
		return played;
	}
	
	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_wa().run();
	}
}
