Buggy python submission (verdict: Time Limit Exceeded):
reverseFlag = False

S = input()
Q = int(input())

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        if reverseFlag:
            reverseFlag = False
        else:
            reverseFlag = True
    else:
        if TFC[1] == '1':
            if reverseFlag:
                S = S + TFC[2]
            else:
                S = TFC[2] + S
        else:
            if reverseFlag:
                S = TFC[2] + S
            else:
                S = S + TFC[2]
if reverseFlag:
    print(S[::-1])
else:
    print(S)

Fixed submission:
reverseFlag = False

S = input()
Q = int(input())
S_mae = ''
S_ato = ''

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        reverseFlag = not reverseFlag
    else:
        if TFC[1] == '1':
            if reverseFlag:
                S_ato = S_ato + TFC[2]
            else:
                S_mae = TFC[2] + S_mae
        else:
            if reverseFlag:
                S_mae = TFC[2] + S_mae
            else:
                S_ato = S_ato + TFC[2]
if reverseFlag:
    print(S_ato[::-1] + S[::-1] + S_mae[::-1])
else:
    print(S_mae + S + S_ato)

Buggy python submission (verdict: Time Limit Exceeded):
reverseFlag = False

S = input()
Q = int(input())

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        if reverseFlag == False:
            reverseFlag = True
        else:
            reverseFlag = False
    else:
        if TFC[1] == '1':
            if reverseFlag == False:
                S = TFC[2] + S
            else:
                S = S + TFC[2]
        else:
            if reverseFlag == True:
                S = TFC[2] + S
            else:
                S = S + TFC[2]
if reverseFlag == True:
    print(S[::-1])
else:
    print(S)

Fixed submission:
reverseFlag = False

S = input()
Q = int(input())
S_mae = ''
S_ato = ''

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        reverseFlag = not reverseFlag
    else:
        if TFC[1] == '1':
            if reverseFlag:
                S_ato = S_ato + TFC[2]
            else:
                S_mae = TFC[2] + S_mae
        else:
            if reverseFlag:
                S_mae = TFC[2] + S_mae
            else:
                S_ato = S_ato + TFC[2]
if reverseFlag:
    print(S_ato[::-1] + S[::-1] + S_mae[::-1])
else:
    print(S_mae + S + S_ato)

Buggy python submission (verdict: Time Limit Exceeded):
reverseFlag = False

S = input()
Q = int(input())

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        S = S[::-1]
    else:
        if TFC[1] == '1':
            S = TFC[2] + S
        else:
            S = S + TFC[2]
print(S)

Fixed submission:
reverseFlag = False

S = input()
Q = int(input())
S_mae = ''
S_ato = ''

for i in range(Q):
    TFC = input().split(' ')
    if TFC[0] == '1':
        reverseFlag = not reverseFlag
    else:
        if TFC[1] == '1':
            if reverseFlag:
                S_ato = S_ato + TFC[2]
            else:
                S_mae = TFC[2] + S_mae
        else:
            if reverseFlag:
                S_mae = TFC[2] + S_mae
            else:
                S_ato = S_ato + TFC[2]
if reverseFlag:
    print(S_ato[::-1] + S[::-1] + S_mae[::-1])
else:
    print(S_mae + S + S_ato)