from enum import IntEnum class Suit(IntEnum): diamond = 1 clover = 2 heart = 3 spade = 4 @classmethod def factory(cls, suit: str): match suit: case "D": return cls.diamond case "C": return cls.clover case "H": return cls.heart case "S": return cls.spade def suit_abb(self): match self: case 1: return "D" case 2: return "C" case 3: return "H" case 4: return "S" class Card: def __init__(self, card: str) -> None: self.suit = Suit.factory(card[0]) match card[1]: case "T": self.number = 10 case "J": self.number = 11 case "Q": self.number = 12 case "K": self.number = 13 case "A": self.number = 1 case other_num: self.number = int(other_num) def str_num(self) -> str: match self.number: case 1: return "A" case 10: return "T" case 11: return "J" case 12: return "Q" case 13: return "K" case other_num: return str(other_num) def __eq__(self, __o: object) -> bool: return self.suit == __o.suit and self.number == __o.number def __ne__(self, __o: object) -> bool: return not self.__eq__(__o) def __lt__(self, __o) -> bool: if self.suit < __o.suit: return True if self.suit == __o.suit: return self.number < __o.number return False def __str__(self) -> str: return self.suit.suit_abb() + self.str_num() def main(): input() cards = list(map(Card, input().split())) cards.sort() print(*cards) if __name__ == "__main__": main()