N = int(input()) lst = [] ans_p = '' ans_s = '' for i in range(N): T,S = input().split(' ') if T == '0': ans_s += S else: ans_p = S + ans_p print(ans_p + ans_s)