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

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

if flag:
    print(ans)
else:
    print(ans[::-1])

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                ans = qry[2] + ans
            else:
                ans += qry[2]
        else:
            if qry[1] == '1':
                ans += qry[2]
            else:
                ans = qry[2] + ans

if flag:
    print(ans)
else:
    print(ans[::-1])

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1' and flag:
        flag = 0
    elif qry[0] == '1' and not flag:
        flag = 1

    elif qry[0] == '2' and flag:
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]
    elif qry[0] == '2' and not flag:
        if qry[1] == '1':
            ans += qry[2]
        elif qry[1] == '2':
            ans = qry[2] + ans

if flag:
    print(ans)
else:
    for i in range(len(ans)//2):
        ans[i], ans[-1-i] = ans[-1-i], ans[i]

    print(ans)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1' and flag:
        flag = 0
    elif qry[0] == '1' and not flag:
        flag = 1

    elif qry[0] == '2' and flag:
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]
    elif qry[0] == '2' and not flag:
        if qry[1] == '1':
            ans += qry[2]
        elif qry[1] == '2':
            ans = qry[2] + ans

if flag:
    print(ans)
else:
    for i in range(len(ans//2)):
        ans[i], ans[-1-i] = ans[-1-i], ans[i]

    print(ans)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

ans = S
flag = 1
for i in range(Q):
    qry = list(input().split())

    if qry[0] == '1' and flag:
        flag = 0
    elif qry[0] == '1' and not flag:
        flag = 1

    elif qry[0] == '2' and flag:
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]
    elif qry[0] == '2' and not flag:
        if qry[1] == '1':
            ans += qry[2]
        elif qry[1] == '2':
            ans = qry[2] + ans

if flag:
    print(ans)
else:
    print(ans[::-1])

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])

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

ans = S
for i in range(Q):
    qry = list(input().split())
    if qry[0] == '1':
        ans = ans[::-1]

    elif qry[0] == '2':
        if qry[1] == '1':
            ans = qry[2] + ans
        elif qry[1] == '2':
            ans += qry[2]

print(ans)

Fixed submission:
from collections import deque

S = deque(input())
Q = int(input())

flag = 1
for i in range(Q):
    qry = input().split()

    if qry[0] == '1':
        if flag:
            flag = 0
        else:
            flag = 1
    
    elif qry[0] == '2':
        if flag:
            if qry[1] == '1':
                S.appendleft(qry[2])
            else:
                S.append(qry[2])
        else:
            if qry[1] == '1':
                S.append(qry[2])
            else:
                S.appendleft(qry[2])

S = ''.join(S)

if flag:
    print(S)
else:
    print(S[::-1])