#include using namespace std; typedef long long ll; typedef vector VI; typedef vector VVI; typedef vector VL; typedef vector VVL; typedef pair PII; #define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i) #define REP(i, n) FOR(i, 0, n) #define ALL(x) x.begin(), x.end() #define MOD 1000000007 #define INF (1LL<<25) //33554432 #define PI 3.14159265359 #define EPS 1e-12 //#define int ll signed main(void) { int n; string s[100]; cin >> n; REP(i, n) cin >> s[i]; vector v; REP(i, n) { int a; if(s[i][0] == 'D') a = 1; if(s[i][0] == 'C') a = 2; if(s[i][0] == 'H') a = 3; if(s[i][0] == 'S') a = 4; int b; if(s[i][1] == 'T') b = 10; else if(s[i][1] == 'J') b = 11; else if(s[i][1] == 'Q') b = 12; else if(s[i][1] == 'K') b = 13; else if(s[i][1] == 'A') b = 1; else b = s[i][1] - '0'; v.push_back(PII(a, b)); } sort(ALL(v)); REP(i, n) { string ans = ""; if(v[i].first == 1) ans += "D"; else if(v[i].first == 2) ans += "C"; else if(v[i].first == 3) ans += "H"; else if(v[i].first == 4) ans += "S"; if(v[i].second == 1) ans += "A"; else if(v[i].second == 10) ans += "T"; else if(v[i].second == 11) ans += "J"; else if(v[i].second == 12) ans += "Q"; else if(v[i].second == 13) ans += "K"; else ans += to_string(v[i].second); cout << ans; if(i != n-1) cout << " "; } return 0; }