#include #define rep(i,n) for(int i = 0; i < (n); ++i) #define drep(i,n) for(int i = (n)-1; i >= 0; --i) using namespace std; int main() { int n; cin >> n; int t[n]; char s[n]; rep(i,n)cin >> t[i] >> s[i]; drep(i,n)if(t[i] == 1)cout << s[i]; rep(i,n)if(t[i] == 0)cout << s[i]; cout << endl; return 0; }