Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
p=0 #front=0 back=1
for i in range(Q):
    A="".join(input().split())
    if A[0]=="1":
        if p==0:p=1
        else:p=0
    else:
        if A[1]=="1":
            if p==0:
                S=A[2]+S
            else:
                S+=A[2]
        else:
            if p==0:
                S+=A[2]
            else:
                S=A[2]+S
                
print(S if p==0 else S[::-1])


Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
rev=False
for i in range(Q):
    A=input().split()
    if A[0]=="1":
        if rev==False:rev=True
        else:rev=False
    else:
        if rev==False:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev:
    S.reverse()
print(*S,sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    A="".join(input().split())
    if A[0]=="1":
        S=S[::-1]
    else:
        if A[1]=="1":
            S=A[2]+S
        else:
            S+=A[2]
print(S)


Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
rev=False
for i in range(Q):
    A=input().split()
    if A[0]=="1":
        if rev==False:rev=True
        else:rev=False
    else:
        if rev==False:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev:
    S.reverse()
print(*S,sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        S=S[::-1]
    else:
        if A[1]=="1":
            S=A[2]+S
        else:
            S=S+A[2]
print(S)


Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
rev=False
for i in range(Q):
    A=input().split()
    if A[0]=="1":
        if rev==False:rev=True
        else:rev=False
    else:
        if rev==False:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev:
    S.reverse()
print(*S,sep="")

Buggy python submission (verdict: Time Limit Exceeded):
S=input()
Q=int(input())
for i in range(Q):
    A=list(input().split())
    if A[0]=="1":
        S=S[::-1]
    else:
        if A[1]=="1":
            S=A[2]+S
        else:
            S=S+A[2]
print(S)


Fixed submission:
from collections import deque
S=deque(input())
Q=int(input())
rev=False
for i in range(Q):
    A=input().split()
    if A[0]=="1":
        if rev==False:rev=True
        else:rev=False
    else:
        if rev==False:
            if A[1]=="1":
                S.appendleft(A[2])
            else:
                S.append(A[2])
        else:
            if A[1]=="1":
                S.append(A[2])
            else:
                S.appendleft(A[2])
if rev:
    S.reverse()
print(*S,sep="")