Buggy python submission (verdict: Time Limit Exceeded):
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
right=""
left=""
center=""
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
        center=right
        right=left[::-1]
        left=center[::-1]
    elif order[0]=="2" and order[1]=="1":
        left=order[2]+left
    elif order[0]=="2" and order[1]=="2":
        right=right+order[2]
if dire==1:
    S=S
elif dire==-1:
    S=S[::-1]
print(left+S+right)

Fixed submission:
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
right=""
left=""
center=""
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
        center=right
        right=left
        left=center
    elif order[0]=="2" and order[1]=="1":
        if dire==1:
            left=order[2]+left
        if dire==-1:
            left=left+order[2]
    elif order[0]=="2" and order[1]=="2":
        if dire==1:
            right=right+order[2]
        if dire==-1:
            right=order[2]+right
if dire==1:
    S=S
    right=right
    left=left
elif dire==-1:
    S=S[::-1]
    right=right[::-1]
    left=left[::-1]
print(left+S+right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
    elif order[0]=="2" and order[1]=="1":
        if dire==-1:
            S=S+order[2]
        if dire==1:
            S=order[2]+S
    elif order[0]=="2" and order[1]=="2":
        if dire==1:
            S=S+order[2]
        if dire==-1:
            S=order[2]+S
if dire==1:
    print(S)
elif dire==-1:
    S=S[::-1]
    print(S)

Fixed submission:
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
right=""
left=""
center=""
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
        center=right
        right=left
        left=center
    elif order[0]=="2" and order[1]=="1":
        if dire==1:
            left=order[2]+left
        if dire==-1:
            left=left+order[2]
    elif order[0]=="2" and order[1]=="2":
        if dire==1:
            right=right+order[2]
        if dire==-1:
            right=order[2]+right
if dire==1:
    S=S
    right=right
    left=left
elif dire==-1:
    S=S[::-1]
    right=right[::-1]
    left=left[::-1]
print(left+S+right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
for order in orders:
    if order[0]=="1":
        S=S[::-1]
    elif order[0]=="2" and order[1]=="1":
        S=order[2]+S
    elif order[0]=="2" and order[1]=="2":
        S=S+order[2]
print(S)

Fixed submission:
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
right=""
left=""
center=""
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
        center=right
        right=left
        left=center
    elif order[0]=="2" and order[1]=="1":
        if dire==1:
            left=order[2]+left
        if dire==-1:
            left=left+order[2]
    elif order[0]=="2" and order[1]=="2":
        if dire==1:
            right=right+order[2]
        if dire==-1:
            right=order[2]+right
if dire==1:
    S=S
    right=right
    left=left
elif dire==-1:
    S=S[::-1]
    right=right[::-1]
    left=left[::-1]
print(left+S+right)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    #print(line)
    orders.append(line.rstrip().split(" "))
#print(orders)
for order in orders:
    if order[0]=="1":
        #print(1)
        S=S[::-1]
    elif order[0]=="2" and order[1]=="1":
        #print(2)
        S=order[2]+S
    elif order[0]=="2" and order[1]=="2":
        #print(3)
        S=S+order[2]
print(S)

Fixed submission:
import sys
S =input()
Q=int(input())
orders=[]
for line in sys.stdin.readlines():
    orders.append(line.rstrip().split(" "))
dire=1
right=""
left=""
center=""
for order in orders:
    if order[0]=="1":
        dire=dire*(-1)
        center=right
        right=left
        left=center
    elif order[0]=="2" and order[1]=="1":
        if dire==1:
            left=order[2]+left
        if dire==-1:
            left=left+order[2]
    elif order[0]=="2" and order[1]=="2":
        if dire==1:
            right=right+order[2]
        if dire==-1:
            right=order[2]+right
if dire==1:
    S=S
    right=right
    left=left
elif dire==-1:
    S=S[::-1]
    right=right[::-1]
    left=left[::-1]
print(left+S+right)