Buggy python submission (verdict: Time Limit Exceeded):
import sys
from collections import deque
input = sys.stdin.readline

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

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S.reverse()
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2])
        elif q[1] == '2':
            S.append(q[2])

print(''.join(S))


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))

Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S.reverse()
    elif q[0] == '2':
        if q[1] == '1':
            S = '{}{}'.format(q[2], S)
        elif q[1] == '2':
            S = '{}{}'.format(S, q[2])

print(S)


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S = S[::-1]
    elif q[0] == '2':
        if q[1] == '1':
            S = '{}{}'.format(q[2], S)
        elif q[1] == '2':
            S = '{}{}'.format(S, q[2])

print(S)


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline

S = input().strip()
Q = int(input())
for i in range(Q):
    q = input().split()
    if q[0] == '1':
        S = S[::-1]
    elif q[0] == '2':
        if q[1] == '1':
            S = q[2] + S
        elif q[1] == '2':
            S = S + q[2]

print(S)


Fixed submission:
import sys
from collections import deque
input = sys.stdin.readline

S = deque(input().strip())
Q = int(input())
flag = 0

for i in range(Q):
    q = input().split()
    if q[0] == '1':
        flag = 1 if not flag else 0
    elif q[0] == '2':
        if q[1] == '1':
            S.appendleft(q[2]) if not flag else S.append(q[2])
        elif q[1] == '2':
            S.append(q[2]) if not flag else S.appendleft(q[2])

print(''.join(S)) if not flag else print(''.join(reversed(S)))