// Arup Guha
// 2/25/2013
// Solution to 2013 Mercer Problem #5: Contest Rules

/*** Note: I am not happy with this solution. Frankly, it's awful. This is just my original design,
 *         and I couldn't think of a way to streamline it nicely. There must be a better way.
 *         This just goes to show that I am not good at text.
 ***/
 
import java.util.*;

public class prob5 {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = Integer.parseInt(stdin.nextLine().trim());
		
		// Loop through cases
		for (int loop=1; loop<=numCases; loop++) {
			
			// Will store each team's info.
			HashMap <String,info> table = processCase(stdin);
			
			// Get all teams and sort.
			Collection<info> temp = table.values();
			ArrayList<info> sortedTeams = new ArrayList<info>();
			for (info x: temp)
				sortedTeams.add(x);
			Collections.sort(sortedTeams);

			// Count the number of each type of team.
			int reg = 0, numReg = 0, remind = 0, cancel = 0;
			for (int i=0; i<sortedTeams.size(); i++) {
				int pts = sortedTeams.get(i).score();
				if (pts == 3) {
					numReg += sortedTeams.get(i).numTeams;
					reg++;
				}
				else if (pts == 2) remind++;
				else cancel++;
			}
			
			// Output each list.
			System.out.println("Contest number "+loop);
			
			if (reg > 0) {
				System.out.println("---"+numReg+" Registered Teams:");
				for (int i=0; i<reg; i++)
					System.out.println(sortedTeams.get(i).name+" ("+sortedTeams.get(i).numTeams+")");
			}
			if (remind > 0) {
				System.out.println("---Send reminders to:");
				for (int i=reg; i<reg+remind; i++)
					System.out.println(sortedTeams.get(i).name);				
			}
			if (cancel > 0) {
				System.out.println("---Cancel registration for:");
				for (int i=reg+remind; i<sortedTeams.size(); i++)
					System.out.println(sortedTeams.get(i).name);				
			}

			if (loop != numCases)
				System.out.println();

		}
		
	}
	
	public static HashMap<String, info> processCase(Scanner stdin) {
		
		// Will store answers.
		HashMap<String,info> table = new HashMap<String,info>();
	
		// Read in all registrations.
		int numReg = Integer.parseInt(stdin.nextLine().trim());
		for (int i=0; i<numReg; i++) {
				
			// Add the team if it's new.
			String team = stdin.nextLine().trim();
			if (!table.containsKey(team)) {
				table.put(team, new info(team,1,true,false,false));
			}
				
			// Adjust school to have one more team.
			else {
				info tmp = table.remove(team);
				tmp.numTeams++;
				table.put(team, tmp);
			}
		}
			
		// Read in who's paid registration.
		int numPay = Integer.parseInt(stdin.nextLine().trim());
		for (int i=0; i<numPay; i++) {
				
			// Add the team if it's new.
			String team = stdin.nextLine().trim();
			if (!table.containsKey(team)) {
				table.put(team, new info(team,1,false,true,false));
			}
				
			// Adjust school to have paid registration.
			else {
				info tmp = table.remove(team);
				tmp.didPay = true;
				table.put(team, tmp);
			}				
		}
			
		// Read in who's paid registration.
		int numMadeProb = Integer.parseInt(stdin.nextLine().trim());
		for (int i=0; i<numMadeProb; i++) {
				
			// Add the team if it's new.
			String team = stdin.nextLine().trim();
			if (!table.containsKey(team)) {
				table.put(team, new info(team,1,false,false,true));
			}
			
			// Adjust school to have given a problem.
			else {
				info tmp = table.remove(team);
				tmp.submitProb = true;
				table.put(team, tmp);
			}				
		}
		
		return table;
	}
}

// Stores a piece of information.
class info implements Comparable<info> {
	
	public String name;
	public int numTeams;
	public boolean registered;
	public boolean didPay;
	public boolean submitProb;
	
	// Stores everything we need.
	public info(String n, int teams, boolean reg, boolean paid, boolean prob) {
		name = n;
		registered = reg;
		numTeams = teams;
		didPay = paid;
		submitProb = prob;
	}
	
	// Requirements met.
	public int score() {
		int sum = 0;
		if (registered) sum++;
		if (didPay) sum++;
		if (submitProb) sum++;
		return sum;
	}
	
	// Sort in order of output.
	public int compareTo(info other) {
		if (this.score() != other.score())
			return other.score() - this.score();
		return this.name.toLowerCase().compareTo(other.name.toLowerCase());
	}
	
}