#include using namespace std; int main(){ int n; cin >> n; string mark = "DCHS"; string num = "0A23456789TJQK"; vector data(n); char x,y; int ret; for(int i = 0; i < n; i++){ cin >> x >> y; if(x == 'D') ret = 0; else if(x == 'C') ret = 13; else if(x == 'H') ret = 26; else ret = 39; if(y == 'A') ret += 1; else if(y == 'T') ret += 10; else if(y == 'J') ret += 11; else if(y == 'Q') ret += 12; else if(y == 'K') ret += 13; else ret += y - '0'; data[i] = ret; } sort(data.begin(),data.end()); for(int i = 0; i < n; i++){ if(i) cout << " "; if(data[i]%13 != 0 ) cout << mark[data[i]/13] << num[data[i]%13]; else cout << mark[data[i]/13-1] << "K"; } cout << endl; return 0; }