Buggy python submission (verdict: Runtime Error):
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(pre+s+suf))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(suf+s+pre))

Fixed submission:
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
for q in qs:
    if len(q) == 1:
        s.reverse()
    else:
        if int(q[1]) == 1:
            s.appendleft(q[2])
        else:
            s.append(q[2])
print("".join(s))

Fixed submission:
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))

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

Fixed submission:
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
qs = [list(input().split()) for i in range(n)]
for q in qs:
    if len(q) == 1:
        s = s[::-1]
    elif len(q) == 3:
        if int(q[1]) == 1:
            s = q[2]+s
        elif int(q[1]) == 2:
            s = s+q[2]
print(s)

Fixed submission:
from collections import deque
s = deque(input())
n = int(input())
qs = [list(input().split()) for i in range(n)]
pre = deque()
suf = deque()
frag = True
for q in qs:
    if len(q) == 1:
        frag = not frag
    else:
        if (frag, q[1]) == (True, "1") or (frag, q[1]) == (False, "2"):
            pre.appendleft(q[2])
        else:
            suf.append(q[2])
if frag is True:
    print("".join(list(pre)+list(s)+list(suf)))
else:
    suf.reverse()
    s.reverse()
    pre.reverse()
    print("".join(list(suf)+list(s)+list(pre)))