Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            S = Query[4] + S
        else:
            S = S + Query[4]

if reverse == True:
    S = S[::-1]


print(S)
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse = not reverse 
    else:
        F = int(Query[2])
        C = Query[4]
        if (F == 1 and reverse == False) or (F == 2 and reverse == True):
            S = C + S
        else:
            S = S + C

if reverse == True:
    S = S[::-1]


print(S)
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse = not reverse 
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F == 1 and reverse == False) or (F == 2 and reverse == True):
            S = C + S
        elif (F == 2 and reverse == False) or (F == 1 and reverse == True):
            S = S + C

if reverse == True:
    S = S[::-1]


print(S)
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse = not reverse 
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F == 1 and reverse == False) or (F == 2 and reverse == True):
            S = C + S
        elif (F == 2 and reverse == False) or (F == 1 and reverse == True):
            S = S + C

if reverse%2 == 1:
    S = S[::-1]


print(S)
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
reverse = False
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse = not reverse 
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F == 1 and reverse == False) or (F == 2 and reverse == True):
            S.insert(0, C)
        elif (F == 2 and reverse == False) or (F == 1 and reverse == True):
            S.append(C)

if reverse%2 == 1:
    S = S[::-1]


print(''.join(S))
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
reverse = 0
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse += 1
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F+reverse)%2 == 1:
            S.insert(0, C)
        elif (F+reverse)%2 == 0:
            S.append(C)

if reverse%2 == 1:
    S = S[::-1]


print(''.join(S))
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
reverse = 0
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        reverse += 1
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if (F+reverse)%2 == 1:
            S.insert(0, C)
        elif (F+reverse)%2 == 0:
            S.append(C)

if reverse%2 == 1:
    temp = list(S)
    for j in range(len(S)):
        S[j] = temp[-1-j]


print(''.join(S))
print('\n')


Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    Query = input()
    T = int(Query[0])
    if T == 1:
        temp = list(S)
        for j in range(len(S)):
            S[j] = temp[-1-j]
    elif T == 2:
        F = int(Query[2])
        C = Query[4]
        if F == 1:
            S.insert(0, C)
        elif F == 2:
            S.append(C)



print(''.join(S))
print('\n')

Fixed submission:
S = input()
Q = int(input())
front = ''
end = ''
reverse = False
for i in range(Q):
    Query = input()
    if Query[0] == '1':
        reverse = not reverse 
    else:
        if (Query[2] == '1' and reverse == False) or (Query[2] == '2' and reverse == True):
            front = Query[4] + front
        else:
            end = end + Query[4]

S = front + S + end
if reverse == True:
    S = S[::-1]


print(S)
print('\n')