Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = input()
num_of_query = int(input())
querys = []
for _ in range(num_of_query):
    # querys.append(list(input().split()))
    query = list(input().split())
    if query[0] == '1':
        S = S[::-1]
    else:
        if query[1] == '1':
            S = deque(S)
            S.appendleft(query[2])
            S = list(S)
        else:
            S = deque(S)
            S.append(query[2])
            S = list(S)


# for query in querys:
#     if query[0] == '1':
#         S = S[::-1]
#     else:
#         if query[1] == '1':
#             S = deque(S)
#             S.appendleft(query[2])
#             S = list(S)
#         else:
#             S = deque(S)
#             S.append(query[2])
#             S = list(S)

print(''.join(S))

Fixed submission:
from collections import deque

S = deque(input())
num_of_query = int(input())
querys = []
is_reverse = False

for _ in range(num_of_query):
    # querys.append(list(input().split()))
    query = list(input().split())
    
    if query[0] == '1':
        is_reverse = not is_reverse
    else:
        if query[1] == '1':
            if is_reverse:
                S.append(query[2])
            else:
                S.appendleft(query[2])

        else:
            if is_reverse:
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = list(S)
if is_reverse:
    S = S[::-1]

# for query in querys:
#     if query[0] == '1':
#         S = S[::-1]
#     else:
#         if query[1] == '1':
#             S = deque(S)
#             S.appendleft(query[2])
#             S = list(S)
#         else:
#             S = deque(S)
#             S.append(query[2])
#             S = list(S)

print(''.join(S))

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

S = input()
num_of_query = int(input())
querys = []
for _ in range(num_of_query):
    querys.append(list(input().split()))

for query in querys:
    if query[0] == '1':
        S = S[::-1]
    else:
        if query[1] == '1':
            S = deque(S)
            S.appendleft(query[2])
            S = list(S)
        else:
            S = deque(S)
            S.append(query[2])
            S = list(S)

print(''.join(S))

Fixed submission:
from collections import deque

S = deque(input())
num_of_query = int(input())
querys = []
is_reverse = False

for _ in range(num_of_query):
    # querys.append(list(input().split()))
    query = list(input().split())
    
    if query[0] == '1':
        is_reverse = not is_reverse
    else:
        if query[1] == '1':
            if is_reverse:
                S.append(query[2])
            else:
                S.appendleft(query[2])

        else:
            if is_reverse:
                S.appendleft(query[2])
            else:
                S.append(query[2])

S = list(S)
if is_reverse:
    S = S[::-1]

# for query in querys:
#     if query[0] == '1':
#         S = S[::-1]
#     else:
#         if query[1] == '1':
#             S = deque(S)
#             S.appendleft(query[2])
#             S = list(S)
#         else:
#             S = deque(S)
#             S.append(query[2])
#             S = list(S)

print(''.join(S))