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

s = deque(input())
q = int(input())

flg_reverse = False


def query_2(s, a, b):
    global flg_reverse
    if flg_reverse is False:
        if a == 2:
            s.append(b)
        elif a == 1:
            s.appendleft(b)
    else:
        if a == 1:
            s.append(b)
        elif a == 2:
            s.appendleft(b)


for i in range(q):
    array = list(input().split())
    if len(array) == 1:
        flg_reverse = not flg_reverse
    else:
        query_2(s, int(array[1]), array[2])

if flg_reverse is False:
    for i in s:
        print(i, end='')
else:
    for i in range(len(s)-1, -1, -1):
        print(s[i], end='')



Fixed submission:
from collections import deque

s = deque(list(input()))
q = int(input())
flg = 1
for i in range(q):
    array = input().split(' ')
    if array[0] == '1':
        flg *= -1
    elif array[0] == '2':
        if array[1] == '1' and flg == 1 or array[1] == '2' and flg == -1:
            s.appendleft(array[2])
        else:
            s.append(array[2])

s = list(s)
if flg == -1:
    s = s[::-1]

s = ''.join(s)
print(s)

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

s = deque(input())
q = int(input())

flg_reverse = False


def query_1():
    global flg_reverse
    if flg_reverse is True:
        flg_reverse = False
    else:
        flg_reverse = True



def query_2(s, a, b):
    global flg_reverse
    if flg_reverse is False:
        if a == 2:
            s.append(b)
        elif a == 1:
            s.appendleft(b)
    else:
        if a == 1:
            s.append(b)
        elif a == 2:
            s.appendleft(b)


for i in range(q):
    array = list(input().split())
    if len(array) == 1:
        query_1()
    else:
        query_2(s, int(array[1]), array[2])

if flg_reverse is False:
    for i in s:
        print(i, end='')
else:
    for i in range(len(s)-1, -1, -1):
        print(s[i], end='')



Fixed submission:
from collections import deque

s = deque(list(input()))
q = int(input())
flg = 1
for i in range(q):
    array = input().split(' ')
    if array[0] == '1':
        flg *= -1
    elif array[0] == '2':
        if array[1] == '1' and flg == 1 or array[1] == '2' and flg == -1:
            s.appendleft(array[2])
        else:
            s.append(array[2])

s = list(s)
if flg == -1:
    s = s[::-1]

s = ''.join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

s = list(s)

flg_reverse = False


def query_1():
    global flg_reverse
    if flg_reverse is True:
        flg_reverse = False
    else:
        flg_reverse = True



def query_2(s, a, b):
    global flg_reverse
    if flg_reverse is False:
        if a == 2:
            s.append(b)
        elif a == 1:
            s.insert(0, b)
    else:
        if a == 1:
            s.append(b)
        elif a == 2:
            s.insert(0, b)


for i in range(q):
    array = list(input().split())
    if len(array) == 1:
        query_1()
    else:
        query_2(s, int(array[1]), array[2])

if flg_reverse is False:
    for i in s:
        print(i, end='')
else:
    for i in range(len(s)-1, -1, -1):
        print(s[i], end='')





Fixed submission:
from collections import deque

s = deque(list(input()))
q = int(input())
flg = 1
for i in range(q):
    array = input().split(' ')
    if array[0] == '1':
        flg *= -1
    elif array[0] == '2':
        if array[1] == '1' and flg == 1 or array[1] == '2' and flg == -1:
            s.appendleft(array[2])
        else:
            s.append(array[2])

s = list(s)
if flg == -1:
    s = s[::-1]

s = ''.join(s)
print(s)

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())

s = list(s)


def query_1():
    global s
    s = s[-1::-1]


def query_2(s, a, b):
    if a == 2:
        s.append(b)
    elif a == 1:
        s.insert(0, b)


for i in range(q):
    array = list(input().split())
    if len(array) == 1:
        query_1()
    else:
        query_2(s, int(array[1]), array[2])

for i in s:
    print(i, end='')




Fixed submission:
from collections import deque

s = deque(list(input()))
q = int(input())
flg = 1
for i in range(q):
    array = input().split(' ')
    if array[0] == '1':
        flg *= -1
    elif array[0] == '2':
        if array[1] == '1' and flg == 1 or array[1] == '2' and flg == -1:
            s.appendleft(array[2])
        else:
            s.append(array[2])

s = list(s)
if flg == -1:
    s = s[::-1]

s = ''.join(s)
print(s)