D={"D":0,"C":14,"H":28,"S":42,"A":1,"T":10,"J":11,"Q":11,"K":13} for i in range(2,10):D[str(i)]=i E={} for d in D.items():E[d[1]]=d[0] N=int(input()) C=input().split() cs=[] for c in C: cs.append((D[c[0]],D[c[1:]])) cs.sort() for i in range(N): print(E[cs[i][0]]+E[cs[i][1]], end=(" " if i!=N-1 else "\n"))