// Arup Guha
// 3/12/2019
// Solution to 2019 UCF HS Contest Problem: Codenames

import java.util.*;

public class codenames {

	final public static int EXTRA = 4;
	
	public static int n;
	public static String[] names;
	public static HashMap<String,Integer> ids;

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = Integer.parseInt(stdin.nextLine().trim());
		
		// Process each case. 
		for (int loop=1; loop<=numCases; loop++) {
			
			// Get data store link from names to ids.
			n = Integer.parseInt(stdin.nextLine().trim());
			names = new String[n];
			ids = new HashMap<String,Integer>();
			
			// Using a trick here to distinguish between two different names that are the same when cleaned.
			for (int i=0; i<n; i++) {
				names[i] = clean(stdin.nextLine())+pad(i);
				ids.put(names[i], i);
			}
			
			// Sort names so we can bucket...
			Arrays.sort(names);
			
			// Will store results here as integers 0 to 26^3-1.
			int[] res = new int[n];
			boolean ok = true;
			
			// Go through data in bins.
			int i=0;
			while (i < n && ok) {
				
				// Identify bin.
				int j=i;
				while (j < n && names[j].charAt(0) == names[i].charAt(0)) j++;
				
				// Just do initials for this bin.
				int[] tmp = solve(i, j-1);
				
				// Can't do it.
				if (tmp == null) ok = false;
				
				// Copy in results.
				else {
					for (int z=0; z<j-i; z++) res[i+z] = tmp[z];
				}
				
				// Update for next bin.
				i = j;
			}
			
			// Case header.
			System.out.println("Event #"+loop+":");
			
			// Easy output case.
			if (!ok)
				System.out.println("Not Possible");
			
			// Need to output initials in appropriate order.
			else {
				
				// First find correct slots and copy appropriate initials to those slots.
				String[] out = new String[n];
				for (int j=0; j<n; j++) {
					int idx = ids.get(names[j]);
					out[idx] = convert(res[j]);
				}
				
				// Ta da!
				for (int j=0; j<n; j++)
					System.out.println(out[j]);
			}
			
			// Blank line.
			System.out.println();
		}
	}
	
	// Makes uppercase and removes spaces.
	public static String clean(String s) {
		s = s.toUpperCase();
		return s.replace(" ", "");
	}
	
	// Creates a four digit string representation of n.
	public static String pad(int n) {
		String res = ""+n;
		while (res.length() < EXTRA) res = "0" + res;
		return res;
	}
	
	// Converts val to its initials (base 26).
	public static String convert(int val) {
		String res = "";
		for (int i=0; i<3; i++) {
			res = (char)(val%26 + 'A') + res;
			val /= 26;
		}
		return res;
	}
	
	// Wrapper function to run brute force.
	public static int[] solve(int s, int e) {
		int[] perm = new int[e-s+1];
		boolean[] used = new boolean[e-s+1];
		int[] res = new int[e-s+1];
		return go(perm, used, s, e, 0);
	}
	
	// Usual permutation function. Tries each permutation of greedily assigning initials.
	public static int[] go(int[] perm, boolean[] used, int s, int e, int k) {
		
		// Made it!
		if (k == e-s+1) return eval(perm, s, e);
		
		// Try each unused item in slot k.
		for (int i=0; i<used.length; i++) {
			if (!used[i]) {
				used[i] = true;
				perm[k] = i;
				int[] tmp = go(perm, used, s, e, k+1);
				if (tmp != null) return tmp;
				used[i] = false;
			}
		}
		
		// Never found a match.
		return null;
	}
	
	// Returns the result of the greedy assignment of names[s..e] in the order specified by perm.
	public static int[] eval(int[] perm, int s, int e) {
		
		// Store what we've used and results here.
		HashSet<Integer> used = new HashSet<Integer>();
		int[] res = new int[e-s+1];
		
		// Greedily go through and assign.
		for (int i=0; i<e-s+1; i++) {
			
			// Assign business names[s+perm[i]].
			boolean asgn = false;
			String business = names[s+perm[i]];
			
			// Just find the first one that works that isn't taken.
			for (int j=1; j<business.length()-EXTRA; j++) {
				for (int k=j+1; k<business.length()-EXTRA; k++) {
					int code = 26*26*(business.charAt(0)-'A') + 26*(business.charAt(j)-'A') + business.charAt(k)-'A';
					if (used.contains(code)) continue;
					used.add(code);
					res[perm[i]] = code;
					asgn = true;
					break;
				}
				if (asgn) break;
			}
			
			// Couldn't do it.
			if (!asgn) return null;
		}
		
		// Ta da!
		return res;
	}
}