Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
#print(list(ans))
A=''
for i in range(len(ans)):
	A+=ans[i]
if c%2==1:
	print(A[::-1])
else:
	print(A)





Fixed submission:
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)

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





Fixed submission:
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)

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





Fixed submission:
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)

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





Fixed submission:
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)

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





Fixed submission:
from collections import deque
ans=deque()
ans.append(str(input()))
q=int(input())
l=[list(map(str,input().split())) for i in range(q)]
#print(l)
c=0
for i in range(q):
	if l[i][0]=='1':
		c+=1
	else:
		if c%2==0:
			if l[i][1]=='1':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
		else:
			if l[i][1]=='2':
				ans.appendleft(l[i][2])
			else:
				ans.append(l[i][2])
A="".join(map(str,list(ans)))
if c%2==1:
	print(A[::-1])
else:
	print(A)