Buggy python submission (verdict: Runtime Error):
import sys
from collections import deque
	S=[input()]
	S=deque(S)
	Q=int(sys.stdin.readline())
	flag=0
	for i in range(Q):
		qu=tuple(input().split())
		if qu[0]=='1':
			if flag==0:
				flag+=1
			else:
				flag=0
		else:
			if qu[1]=='1' and flag==0:
				S.appendleft(qu[2])
			elif qu[1]=='1' and flag==1:
				S.append(qu[2])
			elif qu[1]=='2' and flag==0:
				S.append(qu[2])
			elif qu[1]=='2' and flag==1:
				S.appendleft(qu[2])
	if flag==1:
		S.reverse()
	print(''.join(S))

Fixed submission:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
def main():
	S=input()
	Q=int(sys.stdin.readline())
	flag=0
	for i in range(Q):
		qu=input()
		if qu[0]=='1':
			if flag==0:
				flag+=1
			else:
				flag=0
		else:
			if qu[2]=='1' and flag==0:
				S=qu[4]+S
			elif qu[2]=='1' and flag==1:
				S+=qu[4]
			elif qu[2]=='2' and flag==0:
				S+=qu[4]
			else:
				S=qu[4]+S
	if flag==1:
		S=S[::-1]
	print(S)
if __name__=='__main__':
	main()

Fixed submission:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S=input()
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=input()
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[2]=='1' and flag==0:
			S=qu[4]+S
		elif qu[2]=='1' and flag==1:
			S+=qu[4]
		elif qu[2]=='2' and flag==0:
			S+=qu[4]
		else:
			S=qu[4]+S
if flag==1:
	S=S[::-1]
print(S)

Fixed submission:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S=input()
Q=int(sys.stdin.readline())
for i in range(Q):
	qu=input()
	if qu[0]=='1':
		S=S[::-1]
	else:
		if qu[2]=='1':
			S=qu[4]+S
		else:
			S+=qu[4]
print(S)

Fixed submission:
import sys
from collections import deque
S=[input()]
S=deque(S)
Q=int(sys.stdin.readline())
flag=0
for i in range(Q):
	qu=tuple(input().split())
	if qu[0]=='1':
		if flag==0:
			flag+=1
		else:
			flag=0
	else:
		if qu[1]=='1' and flag==0:
			S.appendleft(qu[2])
		elif qu[1]=='1' and flag==1:
			S.append(qu[2])
		elif qu[1]=='2' and flag==0:
			S.append(qu[2])
		elif qu[1]=='2' and flag==1:
			S.appendleft(qu[2])
if flag==1:
	S=''.join(S)
	S=S[::-1]
	print(S)
	exit()
print(''.join(S))