Buggy python submission (verdict: Time Limit Exceeded):
import sys

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    print(q1[::-1], end='')
    print(S, end='')
    print(q2)
else:
    print(q2[::-1], end='')
    print(S[::-1], end='')
    print(q1)


Fixed submission:
import sys

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    print(q1[::-1], end='')
    print(S, end='')
    print(q2)
else:
    print(q2[::-1], end='')
    print(S[::-1], end='')
    print(q1)

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

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    ans += ''.join(list(reversed(q1)))
    ans += S
    ans += q2
else:
    ans += ''.join(list(reversed(q2)))
    ans += ''.join(list(reversed(S)))
    ans += q1
print(ans)


Fixed submission:
import sys

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    print(q1[::-1], end='')
    print(S, end='')
    print(q2)
else:
    print(q2[::-1], end='')
    print(S[::-1], end='')
    print(q1)

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

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = deque()
q2 = deque()
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        F = int(F)
        if (state + F) % 2 == 1:
            q1.appendleft(C)
        else:
            q2.append(C)

ans = ''
if state == 0:
    while q1:
        ans += q1.popleft()
    ans += S
    while q2:
        ans += q2.popleft()
else:
    while q2:
        ans += q2.pop()
    ans += ''.join(list(reversed(S)))
    while q1:
        ans += q1.pop()
print(ans)


Fixed submission:
import sys

S = input()
Q = int(input())
QUERY = sys.stdin.readlines()

state = 0
q1 = ''
q2 = ''
for i in range(Q):
    query = QUERY[i]
    if query[0] == '1':
        state ^= 1
    else:
        _, F, C = query.split()
        if (state + int(F)) % 2:
            q1 += C
        else:
            q2 += C

ans = ''
if state == 0:
    print(q1[::-1], end='')
    print(S, end='')
    print(q2)
else:
    print(q2[::-1], end='')
    print(S[::-1], end='')
    print(q1)