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

public class game_av_brute {

	FastScanner in;
	PrintWriter out;

	int ans;
	int[] a;
	int k;

	void go(int pos, int cur, int[] count, int sum) {
		int initCur = cur;
		while (cur < count.length && count[cur] > 0) {
			count[cur]--;
			sum--;
			cur++;
		}

		if (pos == a.length) {
			ans = Math.max(ans, cur);
		} else {
			if (sum < k) {
				count[a[pos]]++;
				go(pos + 1, cur, count, sum + 1);
				count[a[pos]]--;
			} else {
				for (int i = 0; i < count.length; i++) {
					if (count[i] > 0) {
						count[i]--;
						count[a[pos]]++;
						go(pos + 1, cur, count, sum);
						count[a[pos]]--;
						count[i]++;
					}
				}
			}
		}

		for (int i = initCur; i < cur; i++) {
			count[i]++;
			sum++;
		}
	}

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

		go(0, 0, new int[m], 0);
		out.println(ans);
	}

	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() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		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_brute().run();
	}
}
