Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            S = x[2] + S
        else:
            S = S + x[2]
if reversecount % 2 == 1:
    S = S[::-1]
print(S)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        d.reverse()
    elif int(x[0]) == 2:
        if int(x[1]) == 1:
            d.appendleft(x[2])
        elif int(x[1]) == 2:
            d.append(x[2])
print(*d, sep='')

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        d.reverse()
    elif int(x[0]) == 2:
        if int(x[1]) == 1:
            d.appendleft(x[2])
        elif int(x[1]) == 2:
            d.append(x[2])
print(*d, sep='')

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
for x in query:
    if int(x[0]) == 1:
        S = S[::-1]
    elif int(x[0]) == 2:
        if int(x[1]) == 1:
            S = x[2] + S
        elif int(x[1]) == 2:
            S = S + x[2]
print(S)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S = S[::-1]
    elif int(query[0]) == 2:
        if int(query[1]) == 1:
            S = query[2] + S
        elif int(query[1]) == 2:
            S = S +query[2]
print(S)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S = S[::-1]
    elif int(query[0]) == 2:
        if int(query[1]) == 1:
            S = query[2] + S
        elif int(query[1]) == 2:
            S = S +query[2]
print(S)

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
Q = int(input())
for i in range(Q):
    query = input().split()
    if int(query[0]) == 1:
        S = S[::-1]
    elif int(query[0]) == 2:
        if int(query[1]) == 1:
            S.insert(0,query[2])
        elif int(query[1]) == 2:
            S.append(query[2])
print(*S ,sep='')

Fixed submission:
from collections import deque
S = input()
Q = int(input())
query = [list(input().split()) for _ in range(Q)]
reversecount = 0
d = deque(S)
for x in query:
    if int(x[0]) == 1:
        reversecount += 1
    else:
        if (int(x[1]) == 1 and (reversecount % 2 == 0)) or (int(x[1]) == 2 and (reversecount % 2 == 1)):
            d.appendleft(x[2])
        else:
            d.append(x[2])
if reversecount % 2 == 1:
    d.reverse()
print(*d, sep='')