#include using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int N; cin >> N; vector H, T; for (int i = 0; i < N; i++) { int t; char s; cin >> t >> s; if (t == 0) { T.emplace_back(s); } else { H.emplace_back(s); } } string res = ""; reverse(H.begin(), H.end()); for (char h : H) { res += h; } for (char t : T) { res += t; } cout << res << '\n'; return 0; }