Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = [S]
for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.insert(0, l[2])
    else:
        t.append(l[2])
ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

ans = S
hanten = 0
for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t = [l[2], ans]
        ans = ''.join(t)
    else:
        t = [ans, l[2]]
        ans = ''.join(t) 
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

ans = S
hanten = 0
for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        ans = l[2] + ans
    else:
        ans = ans + l[2]
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

ans = S
for l in L:
    if len(l) == 1:
        ans = ''.join(list(reversed(ans)))
    elif l[1] == '1':
        ans = l[2] + ans
    else:
        ans = ans + l[2]
print(ans)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
L = [list(input().split()) for i in range(Q)]

hanten = 0
t = deque([S])

for l in L:
    if len(l) == 1:
        hanten += 1
    elif (l[1] == '1' and hanten % 2 == 0) or (l[1] == '2' and hanten % 2 == 1):
        t.appendleft(l[2])
    else:
        t.append(l[2])

ans = ''.join(t)
if hanten % 2 == 1:
    ans = ''.join(list(reversed(ans)))
print(ans)