Buggy python submission (verdict: Runtime Error):
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False

for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])

if not fg:
    q.reverse()

print("".join(q))a



Fixed submission:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
fg = False
que2 = []
que2.append(S)

for _ in range(Q+1):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.append(que[2])
        
ans = "".join(que2)
print(ans)


Fixed submission:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))

Buggy python submission (verdict: Runtime Error):
from collections import deque

S = input()
Q = int(input())
d = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = True
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))


Fixed submission:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))

Buggy python submission (verdict: Runtime Error):
from collections import deque

S = input()
Q = int(input())
L = ""
R = ""
flag = 0

for i in range(Q):
    q = list(map(str , input().split()))
    if q[0] == "1":
        if flag == 0:
            flag = 1
        else:
            flag = 0
    else:
        if q[1] == "1":
            if flag == 0:
                L.append(q[2])
            else:
                R.append(q[2])
        else:
            if flag == 0:
                R.appned(q[2])
            else:
                L.append(q[2])
K = L[::-1] + R

if flag == 0:
    print("".join(K))
else:
    print("".join(K[::-1]))

Fixed submission:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())
que2 = []
que2.append(S)

for _ in range(Q):
    que = list(map(str, input().split()))
    if que[0] == "1":
        que2.reverse()
    elif que[1] == "1":
        que2.insert(0,que[2])
    elif que[1] == "2":
        que2.apend(que[2])
print(que2)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
q = deque(S)
fg = False
for i in range(Q):
    que = list(map(str , input().split()))
    if que[0] == "1":
        fg = not fg
    elif (que[1] == "1" and fg == False) or (que[1] == "2" and fg == True) :
        q.appendleft(que[2])
    else:
        q.append(que[2])
if fg:
    q.reverse()
print("".join(q))