// Arup Guha
// 10/10/2013
// Solution to 2012 UCF HS Contest Problem: Census

import java.util.*;
import java.io.*;

public class census {

	// Will store the number of solutions for this query.
	public static ArrayList<Integer> firstSol;
	public static int numSols;

	public static void main(String[] args) throws Exception {

		Scanner stdin = new Scanner(new File("census.in"));
		int numCases = stdin.nextInt();

		// Go through each case.
		for (int loop=1; loop<=numCases; loop++) {

			// Get info.
			int sum = stdin.nextInt();
			int product = stdin.nextInt();
			int facts = stdin.nextInt();

			// Initial values.
			int numKids = -1;
			firstSol = new ArrayList<Integer>();
			numSols = 0;

			// Go through facts.
			boolean[] factList = new boolean[5];
			boolean changeKids = false;
			for (int i=0; i<facts; i++) {

				String dummy = stdin.next();

				// Read the second string.
				String item = stdin.next();
				boolean flag = true;

				// Hacky trick because I am lazy.
				if (item.charAt(0) == 'T') flag = false;

				// Set a boolean flag or num kids.
				if (item.equals("Oldest")) factList[0] = true;
				else if (item.equals("Youngest")) factList[1] = true;
				else if (item.equals("Middle")) factList[2] = true;
				else if (item.equals("Triplets")) factList[3] = true;
				else if (item.equals("Twins")) factList[4] = true;

				// Mark flag for inconsistent number of kids information.
				else {
					int tempKids = Integer.parseInt(item);
					if (numKids != -1 && tempKids != numKids)
						changeKids = true;
					else
						numKids = tempKids;
				}

				// Other piece of garbage.
				if (flag) dummy = stdin.next();
			}

			// Output results.
			System.out.println("House #"+loop+":");
			solve(sum, product, factList, numKids, changeKids);
			System.out.println();

		}
		stdin.close();
	}

	// Wrapper function.
	public static void solve(int sum, int product, boolean[] factList, int numKids, boolean changeKids) {

		// Trick case.
		if (changeKids) {
			System.out.println("Contradictory Information");
			return;
		}

		// Call recursive function.
		ArrayList<Integer> ages = new ArrayList<Integer>();
		solveRec(sum, product, ages, factList, numKids);

		// Output what is desired.
		if (numSols == 0)
			System.out.println("Contradictory Information");
		else if (numSols > 1)
			System.out.println("Not Enough Information");
		else {
			for (int i=0; i<firstSol.size()-1; i++)
				System.out.print(firstSol.get(i)+" ");
			System.out.println(firstSol.get(firstSol.size()-1));
		}
	}

	// ages stores all ages except 1s...since those slow down the recursion and we can add them back in.
	public static void solveRec(int sum, int product, ArrayList<Integer> ages, boolean[] factList, int numKids) {

		// No more numbers to add.
		if (product == 1) {
			if (consistent(sum, ages, factList, numKids)) {

				// Copy our solution.
				for (int i=0; i<sum; i++)
					firstSol.add(1);
				for (int i=0; i<ages.size(); i++)
					firstSol.add(ages.get(i));
				numSols++;
			}
			return;
		}

		// We filled the array and it doesn't work.
		if (ages.size() == numKids && numKids > 0) return;

		int numAnswers = 0;

		// Set the start point of our search.
		int low = 2;
		if (ages.size() > 0)
			low = ages.get(ages.size()-1);

		// Only possible solution here, so set low.
		if (low > Math.sqrt(product))
			low = product;

		// Try each age next.
		for (int next=low; next<=sum && next<=product; next++) {

			// Not possible ages.
			if (product%next != 0) continue;
			if (ages.size() > 0 && ages.get(ages.size()-1) > next) continue;

			// Add this age to the list and solve recursively.
			ages.add(next);
			solveRec(sum-next, product/next, ages, factList, numKids);
			ages.remove(ages.get(ages.size()-1));
		}
	}

	// Returns true iff this information is consistent.
	public static boolean consistent(int sum, ArrayList<Integer> tempages, boolean[] factList, int numKids) {

		// We need to do this so tempages isn't changed!
		ArrayList<Integer> ages = new ArrayList<Integer>();
		for (int i=0; i<sum; i++)
			ages.add(1);
		for (int i=0; i<tempages.size(); i++)
			ages.add(tempages.get(i));

		int n = ages.size();

		// Inconsistent kid information.
		if (numKids > 0 && n != numKids) return false;

		// Check for oldest and youngest.
		if (factList[0] && n > 1 && ages.get(n-1) == ages.get(n-2)) return false;
		if (factList[1] && n > 1 && ages.get(0) == ages.get(1)) return false;

		// Check middle child rule, with unique age.
		if (factList[2]) {
			if (n%2 == 0)
				return false;
			if (n > 1 && (ages.get(n/2) == ages.get(n/2-1) || ages.get(n/2) == ages.get(n/2+1)))
				return false;
		}

		// Calculate frequencies to look for twins and triplets.
		int[] freq = new int[101];
		for (int i=0; i<ages.size(); i++)
			freq[ages.get(i)]++;

		// Mark twins and triplets.
		boolean hasThree = false;
		boolean hasTwo = false;
		for (int i=0; i<freq.length; i++) {
			if (freq[i] == 2) hasTwo = true;
			if (freq[i] == 3) hasThree = true;
		}

		// Screen out incorrect cases.
		if (factList[3] && !hasThree) return false;
		if (factList[4] && !hasTwo) return false;

		// We made it!
		return true;
	}
}