Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
pre = []
suf = []
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        pre, suf = suf[::-1], pre[::-1]
        rev = not rev
    else:
        if q[1] == '1':
            pre = pre[::-1]
            pre.append(q[2])
            pre = pre[::-1]
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
print(''.join(pre) + S + ''.join(suf))


Fixed submission:
from collections import deque
S = input()
Q = int(input())
pre = deque()
suf = deque()
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = not rev
    else:
        if (not rev and q[1] == '1') or (rev and q[1] == '2'):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
    p = list(suf)[::-1]
    s = list(pre)[::-1]
else:
    p = list(pre)
    s = list(suf)
print(''.join(p) + S + ''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
pre = []
suf = []
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        pre, suf = suf[::-1], pre[::-1]
        S = S[::-1]
    else:
        if q[1] == '1':
            pre = pre[::-1]
            pre.append(q[2])
            pre = pre[::-1]
        else:
            suf.append(q[2])
print(''.join(pre) + S + ''.join(suf))


Fixed submission:
from collections import deque
S = input()
Q = int(input())
pre = deque()
suf = deque()
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = not rev
    else:
        if (not rev and q[1] == '1') or (rev and q[1] == '2'):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
    p = list(suf)[::-1]
    s = list(pre)[::-1]
else:
    p = list(pre)
    s = list(suf)
print(''.join(p) + S + ''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        S = S[::-1]
    else:
        if q[1] == '1':
            S = q[2] + S
        else:
            S = S + q[2]
print(S)


Fixed submission:
from collections import deque
S = input()
Q = int(input())
pre = deque()
suf = deque()
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = not rev
    else:
        if (not rev and q[1] == '1') or (rev and q[1] == '2'):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
    p = list(suf)[::-1]
    s = list(pre)[::-1]
else:
    p = list(pre)
    s = list(suf)
print(''.join(p) + S + ''.join(s))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        S = S[::-1]
    else:
        if q[1] == '1':
            S = q[2] + S
        else:
            S = S + q[2]
print(S)


Fixed submission:
from collections import deque
S = input()
Q = int(input())
pre = deque()
suf = deque()
rev = False
for i in range(Q):
    q = input().split()
    if len(q) == 1:
        rev = not rev
    else:
        if (not rev and q[1] == '1') or (rev and q[1] == '2'):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if rev:
    S = S[::-1]
    p = list(suf)[::-1]
    s = list(pre)[::-1]
else:
    p = list(pre)
    s = list(suf)
print(''.join(p) + S + ''.join(s))