import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import deque q = deque() N = int(readline()) for query in readlines(): if query.startswith(b'0'): f = q.append else: f = q.appendleft s = query.split()[1] f(s) word = b''.join(q).decode() print(word)