Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			s.reverse()
			#print(s)
			flg=0
		if query[1]=='1':
			s.appendleft(query[2])
		else:
			s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=False
for _ in range(q):
	flg=False
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=True
	else:
		if flg:
			s.reverse()
		if query[1]=='1':
			s.appendleft(query[2])
		else:
			s.append(query[2])
if flg:
	s=s[::-1]

print(''.join(s))

Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):
#n=int(input())
#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
for i in range(q):
    t=list(map(str,input().split()))
    if t[0]=='1':
        s=s[::-1]
    else:
        if t[1]=='1':
            s=t[2]+s
        else:
            s=s+t[2]
    t.clear
print(s)


Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):

#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
ans=''
flg=False
for i in range(q):
    t=map(str,input().split())
    if t[0]=='1':
    	flg=True
    else:
		if flg:
			s.reverse()
        if t[1]=='1':
			s=t[2]+s
        else:
            s=s+t[2]
    ans=s
print(s)

Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Runtime Error):

#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
ans=''
flg=False
for i in range(q):
    t=map(str,input().split())
    if t[0]=='1':
    	flg=True
    else:
		if flg:
			s.reverse()
        if t[1]=='1':
			s=t[2]+s
        else:
            s=s+t[2]
    ans=s
print(s)

Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
#n=int(input())
#n,m=map(int,input().split())
#a=[int(x) for _ in input().split()]

s=input()
q=int(input())
for i in range(q):
    t=list(map(str,input().split()))
    if t[0]=='1':
        s=s[::-1]
    else:
        if t[1]=='1':
            s=t[2]+s
        else:
            s=s+t[2]
    t.clear
print(s)

Fixed submission:
from collections import deque

s=input()
s=deque(s)
q=int(input())
ans=''
flg=0
for _ in range(q):
	query=list(map(str,input().split()))
	if query[0]=='1':
		flg=1-flg
	else:
		if flg:
			if query[1]=='1':
				s.append(query[2])
			else:
				s.appendleft(query[2])
		else:
			if query[1]=='1':
				s.appendleft(query[2])
			else:
				s.append(query[2])
if flg:
	t=[]
	for i in range(len(s)):
		t.append(s.pop())
	print(''.join(t))
else:
    print(''.join(s))