#include using namespace std; int main() { int N; cin >> N; vector T(N); vector S(N); for (int i = 0; i < N; ++i) { cin >> T[i] >> S[i]; } deque dq; for (int i = 0; i < N; ++i) { if (T[i] == 0) { dq.push_back(S[i]); } else { dq.push_front(S[i]); } } while (!dq.empty()) { cout << dq.front(); dq.pop_front(); } cout << endl; }