Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)

Fixed submission:
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)

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

Fixed submission:
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]

for i in sousa:
    if i[0]=='1':
        S=S[::-1]
    if i[0]=='2':
        if i[1]=='1':
            S=i[2]+S
        if i[1]=='2':
            S=S+i[2]
print(S)

Fixed submission:
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]

for i in sousa:
    if int(i[0])==1:
        S=S[::-1]
    if int(i[0])==2:
        if int(i[1])==1:
            S=i[2]+S
        if int(i[1])==2:
            S=S+i[2]
print(S)

Fixed submission:
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]

for i in sousa:
    if int(i[0])==1:
        S=S[::-1]
    if int(i[0])==2:
        if int(i[1])==1:
            S=i[2]+S
        if int(i[1])==2:
            S=S+i[2]
print(S)

Fixed submission:
S=input()
Q=int(input())
sousa=[list(map(str,input().split())) for i in range(Q)]
counter=0
up=''
down=''
for i in sousa:
    if i[0]=='1':
#         S=S[::-1]
        counter+=1
    if i[0]=='2':
        if counter%2==0:
            if i[1]=='1':
                up=i[2]+up
            if i[1]=='2':
                down=down+i[2]
        else:
            if i[1]=='1':
                down=down+i[2]
            if i[1]=='2':
                up=i[2]+up   
                
S=up+S+down
if counter%2==1:
    S=S[::-1]

print(S)