#include using namespace std; int n,z,i; main(){ cin>>n; deque A; for(i=0;n>i;i++){char y;cin>>z>>y;if(z)A.push_front(y);else A.push_back(y);} for(i=0;n>i;i++){cout<