Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
N = int(input())


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            S.insert(0,order[2])
        else:
            S.append(order[2])
    elif order[0] == '1':
        if state:
            state = False
        else:
            state = True


if state:
    out = ''.join(S)
else:
    out = ''.join(S[::-1])

print(out)

Fixed submission:
S = list(str(input()))
N = int(input())

top = []
end = []


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            top.append(order[2])
        else:
            end.append(order[2])
    elif state:
        state = False
    else:
        state = True


if state:
    S = ''.join(S)
    top = ''.join(top[::-1])
    end = ''.join(end)
    out = top + S + end
    
else:
    S = ''.join(S[::-1])
    top = ''.join(top)
    end = ''.join(end[::-1])
    out = end + S + top

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(str(input()))
N = int(input())


order = []
state = True

for n in range(N):
    order.append(input().split())


for n in range(N):
    if order[n][0] == '2':
        if (order[n][1] == '1') == state:
            S.insert(0,order[n][2])
        else:
            S.append(order[n][2])
    elif order[n][0] == '1':
        if state:
            state = False
        else:
            state = True


if state:
    out = ''.join(S)
else:
    out = ''.join(S[::-1])

print(out)

Fixed submission:
S = list(str(input()))
N = int(input())

top = []
end = []


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            top.append(order[2])
        else:
            end.append(order[2])
    elif state:
        state = False
    else:
        state = True


if state:
    S = ''.join(S)
    top = ''.join(top[::-1])
    end = ''.join(end)
    out = top + S + end
    
else:
    S = ''.join(S[::-1])
    top = ''.join(top)
    end = ''.join(end[::-1])
    out = end + S + top

print(out)

Buggy python submission (verdict: Time Limit Exceeded):
S = str(input())
N = int(input())

order = []
state = True

for n in range(N):
    order.append(input().split())


for n in range(N):
    if order[n][0] == '2':
        if (order[n][1] == '1') == state:
            S = order[n][2] + S
        else:
            S = S + order[n][2]
    elif order[n][0] == '1':
        if state:
            state = False
        else:
            state = True


if state:
    out = S
else:
    out = S[::-1]

print(out)

Fixed submission:
S = list(str(input()))
N = int(input())

top = []
end = []


order = []
state = True

for n in range(N):
    order = input().split()
    if order[0] == '2':
        if (order[1] == '1') == state:
            top.append(order[2])
        else:
            end.append(order[2])
    elif state:
        state = False
    else:
        state = True


if state:
    S = ''.join(S)
    top = ''.join(top[::-1])
    end = ''.join(end)
    out = top + S + end
    
else:
    S = ''.join(S[::-1])
    top = ''.join(top)
    end = ''.join(end[::-1])
    out = end + S + top

print(out)