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

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B = B[::-1]
    print(''.join(B))

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = []
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    C = []
    A = list(map(str, input().split()))
    if len(A) == 3:
        C.append(A[2])
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B = C + B
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B = C + B
if res == 0:
    print(''.join(B))
else:
    B = B[::-1]
    print(''.join(B))

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = []
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    C = []
    A = list(map(str, input().split()))
    if len(A) == 3:
        C.append(A[2])
    if int(A[0]) == 1:
        B = B[::-1]
    else:
        if int(A[1]) == 1:
            B = C + B
        else:
            B.append(A[2])
print(''.join(B))

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = []
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    C = []
    A = list(map(str, input().split()))
    if len(A) == 3:
        C.append(A[2])
    if int(A[0]) == 1:
        B = B[::-1]
    else:
        if int(A[1]) == 1:
            B = C + B
        else:
            B.append(A[2])
print(''.join(B))

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
B = []
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    C = []
    A = list(map(str, input().split()))
    if len(A) == 3:
        C.append(A[2])
    if int(A[0]) == 1:
        B.reverse()
    else:
        if int(A[1]) == 1:
            B = C + B
        else:
            B.append(A[2])
print(''.join(B))

Fixed submission:
from collections import deque

S = input()
B = deque()
res = 0
for s in range(len(S)):
    B.append(S[s])
Q = int(input())
for q in range(Q):
    A = list(map(str, input().split()))
    if int(A[0]) == 1:
        if res == 0:
            res = 1
        else:
            res = 0
    else:
        if int(A[1]) == 1:
            if res == 0:
                B.appendleft(A[2])
            else:
                B.append(A[2])
        else:
            if res == 0:
                B.append(A[2])
            else:
                B.appendleft(A[2])
if res == 0:
    print(''.join(B))
else:
    B.reverse()
    print(''.join(B))