// Arup Guha
// 4/12/2019
// Solution to Code Jam Round 1A Problem: Golf Gophers (written in contest commented later)

import java.util.*;

public class c {

	public static int[] guess = {3,4,5,7,11,13,17};
	public static void main(String[] args) {
	
		// Get basic input.
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		int n = stdin.nextInt();
		int max = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<nC; loop++) {
		
			int[] res = new int[guess.length];
			
			// This is the number of queries I always make.
			for (int i=0; i<guess.length; i++) {
			
				// The key is to keep all 18 the same, so that the sum of the turns
				// gives me valuable mod information.
				for (int j=0; j<18; j++) {
					System.out.print(guess[i]);
					if (j < 17) System.out.print(" ");
				}
				System.out.println();
				System.out.flush();
			
				// Since the windmills are all the same size, I can infer X % guess[i] where X is the # of gophers.
				int sum = 0;
				for (int j=0; j<18; j++)
					sum += stdin.nextInt();
				res[i] = sum%guess[i];
			}
		
			// Instead of doing CRT, since we know the answer is 1 to 1,000,000 just try everything =)
			int ans = -1;
		
			// Try each value.
			for (int i=1; i<=max; i++) {
			
				// Just need to check if the seven mods check out.
				boolean ok = true;
				for (int j=0; j<guess.length; j++)
					if (i%guess[j] != res[j])
						ok = false;
				
				// If they did, we have our answer, get out.
				if (ok) {
					ans = i;
					break;
				}
			}
		
			// Ta da!
			System.out.println(ans);
			System.out.flush();
			int tmp = stdin.nextInt();
		}
	}
}