from collections import deque N = int(input()) ans = deque() for i in range(N): T, S = input().split() if T == "0": ans.append(S) else: ans.appendleft(S) for s in ans: print(s, end="") print()