// Arup Guha
// 2/24/2020
// Alternate solution to 2020 Mercer Problem: Motif Finding
// Note: This takes 4 seconds on my laptop on the data.

import java.util.*;

public class motif_arup_backtrack {

	public static int n;
	public static int numBits;
	public static int maxDiff;
	public static long[] nums;
	
	public static void main(String[] args) {
	
		Scanner stdin =  new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process each case.
		for (int loop=1; loop<=nC; loop++) {
		
			// Get input.
			n = stdin.nextInt();
			numBits = stdin.nextInt();
			maxDiff = stdin.nextInt();
			nums= new long[n];
			for (int i=0; i<n; i++)
				nums[i] = stdin.nextLong();
				
			// Run it!
			System.out.println("Case "+loop+": Matching Motifs");
			go(numBits-1, 0, new int[n]);
			System.out.println();
		}
	}
	
	// cur is the current number we are testing, k is the current bit we 
	// are filling in and numdiff[i] shows how many differences we've already
	// built up in previous bits for the ith value in the input array.
	public static void go(int k, long cur, int[] numdiff) {
	
		// Get rid of bad bit counts. This is the backtracking in this solution.
		if (badNumDiff(numdiff)) return;
		
		// Base case.
		if (k == -1) {
			System.out.println(cur);
			return;
		}
		
		// Try both bits.
		for (int bit=0; bit<2; bit++) {
		
			// I just recalculate this in a new array because it seemed too annoying
			// to rememeber and undo the changes in the same array.
			// Use bitwise ops to isolate the kth bit and see if it's different
			// than bit or not.
			int[] newNumDiff = new int[n];
			for (int i=0; i<n; i++) 
				newNumDiff[i] = (int)(numdiff[i] + (((nums[i]>>k)&1)^bit));
				
			// Natural recursion...I am counting down with k so I can go through
			// the possible answers in order.
			go(k-1, cur+(1L<<k)*bit, newNumDiff);
		}
		
	}
	
	// Returns true iff any entry in numdiff is greater than the maximum number of
	// differences allowed.
	public static boolean badNumDiff(int[] numdiff) {
		for (int i=0; i<numdiff.length; i++)
			if (numdiff[i] > maxDiff)
				return true;
		return false;
	}
}