Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

mod = 0 #反転が何回目か（先頭がどっちか）,偶数回の時0，奇数回の時1

for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            if mod == 0:
                S = Query[4] + S
            else:
                S = S + Query[4]
        else:
            if mod == 0:
                S = S + Query[4]
            else:
                S = Query[4] + S
    #print("Qans",S)
if mod==0:
    print(S)
else:
    print(S[::-1])

Fixed submission:
from collections import deque

S = input()
Q = int(input())
d = deque(S)
#print(d)

mod = 0 #反転が何回目か（先頭がどっちか）,偶数回の時0，奇数回の時1

for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            if mod == 0:
                d.appendleft(Query[4])
            else:
                d.append(Query[4])
        else:
            if mod == 0:
                d.append(Query[4])
            else:
                d.appendleft(Query[4])

S = ""
if mod==0:
    for _ in range(len(d)):
        S += d.popleft()
else:
    for _ in range(len(d)):
        S += d.pop()
print(S)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())

f, l = S[0],S[-1]

mod = 0
for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        f, l = l, f #swap
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            f = Query[4]
            if mod == 0:
                S = f + S
            else:
                s = s + f
        else:
            l = Query[4]
            if mod == 0:
                S = S + l
            else:
                S = l + S
    #print("Qans",S)

if mod==0:
    print(S)
else:
    print(S[::-1])

Fixed submission:
from collections import deque

S = input()
Q = int(input())
d = deque(S)
#print(d)

mod = 0 #反転が何回目か（先頭がどっちか）,偶数回の時0，奇数回の時1

for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            if mod == 0:
                d.appendleft(Query[4])
            else:
                d.append(Query[4])
        else:
            if mod == 0:
                d.append(Query[4])
            else:
                d.appendleft(Query[4])

S = ""
if mod==0:
    for _ in range(len(d)):
        S += d.popleft()
else:
    for _ in range(len(d)):
        S += d.pop()
print(S)

Buggy python submission (verdict: Runtime Error):
S = input()
Q = int(input())

f, l = S[0],S[-1]

mod = 0
for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        f, l = l, f #swap
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            f = Query[4]
            if mod == 0:
                S = f + S
            else:
                s = s + f
        else:
            l = Query[4]
            if mod == 0:
                S = S + l
            else:
                S = l + S
    #print("Qans",S)

print(S)

Fixed submission:
from collections import deque

S = input()
Q = int(input())
d = deque(S)
#print(d)

mod = 0 #反転が何回目か（先頭がどっちか）,偶数回の時0，奇数回の時1

for _ in range(Q):
    Query = input()
    if Query[0] == "1":
        mod = (1 + mod) % 2
    else:
        if Query[2] == "1":
            if mod == 0:
                d.appendleft(Query[4])
            else:
                d.append(Query[4])
        else:
            if mod == 0:
                d.append(Query[4])
            else:
                d.appendleft(Query[4])

S = ""
if mod==0:
    for _ in range(len(d)):
        S += d.popleft()
else:
    for _ in range(len(d)):
        S += d.pop()
print(S)