import java.util.*; public class Exercise86{ public static void main (String[] args){ Scanner sc = new Scanner(System.in); ArrayList> array = new ArrayList>(); for(int i = 0; i < 4; i++){ array.add(new ArrayList()); } int n = sc.nextInt(); for(int i = 0; i < n; i++){ String x = sc.next(); if(x.contains("D")){ x = changeNum(x); x = x.replace("D", ""); array.get(0).add(Integer.parseInt(x)); }else if(x.contains("C")){ x = changeNum(x); x = x.replace("C", ""); array.get(1).add(Integer.parseInt(x)); }else if(x.contains("H")){ x = changeNum(x); x = x.replace("H", ""); array.get(2).add(Integer.parseInt(x)); }else if(x.contains("S")){ x = changeNum(x); x = x.replace("S", ""); array.get(3).add(Integer.parseInt(x)); } } for(int i = 0; i < array.size(); i++){ Collections.sort(array.get(i)); } String answer = ""; for(int i = 0; i < array.size(); i++){ for(int j = 0; j < array.get(i).size(); j++){ String y = changeNum(String.valueOf(array.get(i).get(j))); if(i == 0){ answer += "D"; }else if(i == 1){ answer += "C"; }else if(i == 2){ answer += "H"; }else if(i == 3){ answer += "S"; } answer += y + " "; } } System.out.println(answer); } private static String changeNum(String x){ if (x.contains("T")){ x = x.replace("T", "10"); return x; }else if(x.contains("J")){ x = x.replace("J", "11"); return x; }else if(x.contains("Q")){ x = x.replace("Q", "12"); return x; }else if(x.contains("K")){ x = x.replace("K", "13"); return x; }else if(x.contains("A")){ x = x.replace("A", "1"); return x; }else if(x.contains("10")){ x = x.replace("10", "T"); return x; }else if(x.contains("11")){ x = x.replace("11", "J"); return x; }else if(x.contains("12")){ x = x.replace("12", "Q"); return x; }else if(x.contains("13")){ x = x.replace("13", "K"); return x; }else if(x.contains("1")){ x = x.replace("1", "A"); return x; } return x; } }