N=int(raw_input()) markTable=['D','C','H','S'] numTable=['A','2','3','4','5','6','7','8','9','T','J','Q','K'] def trans(card): ret=[1,1] for i,c in enumerate(markTable): if c==card[0]: ret[0]=i for i,c in enumerate(numTable): if c==card[1]: ret[1]=i return ret Cards=map(trans,raw_input().split()) Cards.sort() for p,q in Cards: print "%c%c" % (markTable[p],numTable[q]),