Buggy python submission (verdict: Runtime Error):
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    if key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])


Fixed submission:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '1':
        key = -key
    
    elif (i[2] == '1' and key == 1) or (i[2] == '2' and key == -1):
        S = i[4] + S
    else:
        S = S + i[4]


print(S[::key])

Fixed submission:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '1':
        key = -key
    
    elif (i[2] == '1' and key == 1) or (i[2] == '2' and key == -1):
        S = i[4] + S
    else:
        S = S + i[4]


print(S[::key])

Fixed submission:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])

Buggy python submission (verdict: Time Limit Exceeded):
import sys
S = input()
Q = int(input())

for i in sys.stdin:
    if i[0] == '1':
        S = S[::-1]
    
    elif i[2] == '1':
        S = i[4] + S
    else:
        S = S + i[4]

print(S)

Fixed submission:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])

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

for i in range(Q):
    queryi = input()
    if queryi == '1':
        S = S[::-1]
    
    else:
        T, F, C = queryi.split()
        if F == '1':
            S = C + S
        else:
            S = S + C

print(S)

Fixed submission:
import sys
S = input()
Q = int(input())
key = 1

for i in sys.stdin:
    if i[0] == '0':
        break

    if i[0] == '1':
        key = -key
    
    elif key == 1:
        if i[2] == '1':
            S = i[4] + S
        else:
            S = S + i[4]

    else:
        if i[2] == '2':
            S = i[4] + S
        else:
            S = S + i[4]


print(S[::key])