using System; using System.Collections; using System.Collections.Generic; using System.Collections.Specialized; using System.Text; using System.Text.RegularExpressions; using System.Linq; using System.IO; class Magatro { static int N; static string[] m; static void Main() { Scan(); Array.Sort(m, Compare); Console.WriteLine(string.Join(" ", m)); } static int Compare(string a,string b) { int atype = Type(a[0]); int btype = Type(b[0]); if (atype > btype) return 1; else if (atype < btype) return -1; else { int anum = Num(a[1]); int bnum = Num(b[1]); return anum.CompareTo(bnum); } } static int Num(char m) { switch (m) { case 'A': return 1; case 'T': return 10; case 'J': return 11; case 'Q': return 12; case 'K': return 13; } int result; if (int.TryParse(m.ToString(), out result)) { return result; } else { throw new Exception(); } } static int Type(char m) { switch (m) { case 'D': return 0; case 'C': return 1; case 'H': return 2; case 'S': return 3; default: throw new Exception(); } } static void Scan() { Scanner sc = new Scanner(); N = sc.NextInt(); m = new string[N]; for(int i = 0; i < N; i++) { m[i] = sc.Next(); } } } public class Scanner { public string[] S; private int Index; private char Separator; public Scanner(char separator=' ') { Index = 0; Separator = separator; } private string[] Line() { return Console.ReadLine().Split(Separator); } public string Next() { string result; if (S == null || Index >= S.Length) { S = Line(); Index = 0; } result = S[Index]; Index++; return result; } public int NextInt() { return int.Parse(Next()); } public double NextDouble() { return double.Parse(Next()); } public long NextLong() { return long.Parse(Next()); } }