// Arup Guha
// 4/11/2016
// Solution to 2016 Code Jam Qualification Problem C: Coin Jam
// Note: I did get this correct in contest, but wrote two different solutions. So I cleaned up my large solution
//       and retested it on both sample files (small, large).

import java.util.*;
import java.math.*;

public class c {

	public static BigInteger[][] table;
	public static BigInteger[] digits;
	public static void main(String[] args) {

		// Storing each digit (and 10) as a big integer.
		digits = new BigInteger[11];
		for (int i=0; i<11; i++)
			digits[i] = new BigInteger(""+i);

		// Storing all powers of integers 2 to 10 here.
		table = new BigInteger[11][32];
		for (int i=0; i<=10; i++)
			table[i][0] = new BigInteger("1");

		// Calculate them.
		for (int i=2; i<=10; i++)
			for (int j=1; j<=31; j++)
				table[i][j] = table[i][j-1].multiply(digits[i]);

		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();

		// Process each case.
		for (int loop=1; loop<=numCases; loop++) {

			System.out.println("Case #"+loop+":");

			// Get this input.
			int n = stdin.nextInt();
			int max = stdin.nextInt();
			int printed = 0;

			// This loop just checks each possible item, in order.
			for (long i=(1L<<(n-1))+1; i<(1L<<n); i+=2) {

				// We've found enough items, so get out.
				if (printed == max) break;

				// Build the list of each actual value in base 10.
				BigInteger[] list = new BigInteger[11];
				for (int base=2; base<=10; base++)
					list[base] = getBigInt(i, n, base);

				// Try to look for factors of each of these numbers. The trick - stop at 1000 so we skip
				// over any numbers that are hard to prove composite. We can do this is the density of what
				// we're looking for is much higher than we need, so we can afford to skip lots of actual
				// candidates and just verify easy ones.
				int[] factors = new int[11];
				boolean okay = true;
				for (int j=2; j<=10; j++) {
					factors[j] = getFactor(list[j]);
					if (factors[j] == -1) {
						okay = false;
						break;
					}
				}

				// This didn't work out.
				if (!okay) continue;

				// Found a solution!
				System.out.print(Long.toBinaryString(i));

				// Print it.
				for (int j=2; j<=10; j++)
					System.out.print(" "+factors[j]);
				System.out.println();
				printed++;
			}

			// Irrelevant since there is one input case, but I just wanted to code it generally.
			if (loop < numCases) System.out.println();
		}
	}

	// Returns the value val in the base base. Val must have size bits.
	public static BigInteger getBigInt(long val, int size, int base) {
		BigInteger res = new BigInteger("0");
		for (int i=0; i<size; i++) {
			if  ( ((val>>i)&1L) == 1L)
				res = res.add(table[base][i]);
		}
		return res;
	}

	// Returns the first integer factor of b less than 1000. If none is found, -1 is returned.
	public static int getFactor(BigInteger b) {
		for (int i=2; i<1000; i++)
			if (b.mod(new BigInteger(""+i)).equals(BigInteger.ZERO))
				return i;

		return -1;
	}
}
