Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                S = query[2] + S
            else:
                S = S + query[2]
        if query[1] == '2':
            if not reverse:
                S = S + query[2]
            else:
                S = query[2] + S

if not reverse:
    print(S)
else:
    print(S[::-1])


Fixed submission:
S = input()
Q = int(input())

front = ''
back = S
reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                front = front + query[2]
            else:
                back = back + query[2]
        if query[1] == '2':
            if not reverse:
                back = back + query[2]
            else:
                front = front + query[2]

if not reverse:
    print(front[::-1] + back)
else:
    print(back[::-1] + front)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                S = query[2] + S
            else:
                S = S + query[2]
        if query[1] == '2':
            if not reverse:
                S = S + query[2]
            else:
                S = query[2] + S

if not reverse:
    print(S)
else:
    print(S[::-1])


Fixed submission:
S = input()
Q = int(input())

front = ''
back = S
reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                front = front + query[2]
            else:
                back = back + query[2]
        if query[1] == '2':
            if not reverse:
                back = back + query[2]
            else:
                front = front + query[2]

if not reverse:
    print(front[::-1] + back)
else:
    print(back[::-1] + front)

Buggy python submission (verdict: Time Limit Exceeded):
S = input()
Q = int(input())

reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                S = query[2] + S
            else:
                S = S + query[2]
        if query[1] == '2':
            if not reverse:
                S = S + query[2]
            else:
                S = query[2] + S

if not reverse:
    print(S)
else:
    for i in range(1, len(S)+1):
        print(S[-i], end='')


Fixed submission:
S = input()
Q = int(input())

front = ''
back = S
reverse = False

for i in range(Q):
    query = input().split()
    if query[0] == '1':
        reverse = not reverse
    if query[0] == '2':
        if query[1] == '1':
            if not reverse:
                front = front + query[2]
            else:
                back = back + query[2]
        if query[1] == '2':
            if not reverse:
                back = back + query[2]
            else:
                front = front + query[2]

if not reverse:
    print(front[::-1] + back)
else:
    print(back[::-1] + front)