public static void main (String args[]) throws Exception {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String line = reader.readLine();
		int number = Integer.parseInt(line);

		line = reader.readLine();
		StringTokenizer st = new StringTokenizer(line);

		Queue<String>[] queueNumber = new LinkedList[9];
		for (int i=0; i<9; i++) {
			queueNumber[i] = new LinkedList<String>();
		}
		Queue<String>[] queueLetter = new LinkedList[4];
		for (int i=0; i<4; i++) {
			queueLetter[i] = new LinkedList<String>();
		}

		for (int i=0; i<number; i++) {
			String tempPoker = st.nextToken();
			queueNumber[tempPoker.charAt(1)-49].add(tempPoker);
		}

		String strPrint;
		for (int i=0; i<9; i++) {
			strPrint = "Queue" + (i+1) + ":";
			for (String currentPoker : queueNumber[i]) {
				queueLetter[currentPoker.charAt(0)-65].add(currentPoker);
				strPrint += currentPoker + " ";
			}
			System.out.println(strPrint);
		}

		String strOutput = "";
		for (int i=0; i<4; i++) {
			strPrint = "Queue" + (char)(i+65) + ":";
			for (String currentPoker : queueLetter[i]) {
				strPrint += currentPoker + " ";
				strOutput += currentPoker + " ";
			}
			System.out.println(strPrint);
		}

		System.out.println(strOutput);
	}