Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
revflag = 1
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			s = tfc[2] + s
		else:
			s = s + tfc[2]
	else:
		if revflag > 0:
			s += tfc[2]
		else:
			s = tfc[2] + s
if revflag > 0:
	print(s)
else:
	print(s[::-1])

Fixed submission:
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
for i in range(q):
	t, f, c = map(str, input().split())
	if t == '1':
		s = s[::-1]
	elif f == '1':
			s = c + s
	else:
			s += c
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))

Buggy python submission (verdict: Runtime Error):
s = input()
q = int(input())
for i in range(q):
	t, f, c = map(str, input().split())
	if t == '1':
		s = s[::-1]
	elif f == '1':
			s = c + s
	else:
			s += c
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		s = s[::-1]
	elif tfc[1] == '1':
			s = tfc[2] + s
	else:
			s += tfc[2]
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		s = s[::-1]
	if tfc[0] == '2':
		if tfc[1] == '1':
			s = tfc[2] + s
		if tfc[1] == '2':
			s += tfc[2]
print(s)

Fixed submission:
from collections import deque

s = input()
q = int(input())
revflag = 1
d = deque(s)
for i in range(q):
	tfc = list(map(str, input().split()))
	if tfc[0] == '1':
		revflag *= -1
	elif tfc[1] == '1':
		if revflag > 0:
			d.appendleft(tfc[2])
		else:
			d.append(tfc[2])
	else:
		if revflag > 0:
			d.append(tfc[2])
		else:
			d.appendleft(tfc[2])
if revflag > 0:
	print(''.join(d))
else:
	print(''.join(reversed(d)))