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

import static java.lang.Math.*;

public class game_as {
    public void run() throws IOException {
        in = new FastScanner(new FileInputStream("game.in"));
        out = new PrintWriter("game.out");

        int testNo = in.nextInt();

        for (int test = 0; test < testNo; test++) {
            int n = in.nextInt();
            int m = in.nextInt();
            int k = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt() - 1;
            }

            int L = 0;
            int R = m + 1;
            while (L < R - 1) {
                int v = (L + R) / 2;
                boolean[] wait = new boolean[v];
                for (int j = v - 1; j >= v - k && j >= 0; j--) {
                    wait[j] = true;
                }
                int next = v - k - 1;
                int put = 0;
                for (int i = n - 1; i >= 0; i--) {
                    if (a[i] < v) {
                        if (wait[a[i]]) {
                            wait[a[i]] = false;
                            put++;
                            if (next >= 0) {
                                wait[next] = true;
                                next--;
                            }
                        }
                    }
                }
                if (put == v) {
                    L = v;
                } else {
                    R = v;
                }
            }

            out.println(L);
        }

        out.close();
    }

    FastScanner in;
    PrintWriter out;

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

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream in) throws IOException {
            br = new BufferedReader(new InputStreamReader(in));
        }

        String next() {
            try {
                while (st == null || !st.hasMoreTokens()) {
                    st = new StringTokenizer(br.readLine());
                }
            } catch (IOException e) {
                System.err.println(e);
                System.exit(1);
            }
            return st.nextToken();
        }

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

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