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

head = []
div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s = q[2] + s
    else:
        s = s + q[2]


if div:
    print(s)
else:
    s = s[::-1]
    print(s)


Fixed submission:
from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

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

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s = q[2] + s
    else:
        s = s + q[2]


if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


Fixed submission:
from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
qs = [input().split(' ') for i in range(n)]

div = True
for q in qs:
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        s = q[2] + s
    else:
        s = s + q[2]


if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


Fixed submission:
from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
qs = [input().split(' ') for i in range(n)]

div = True
for q in qs:
    if q[0] == '1':
        div = not div
    else:
        if (q[1] == '1' and div) or (q[1] == '2' and not div):
            s = q[2] + s
        else:
            s = s + q[2]


if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


Fixed submission:
from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
n = int(input())
qs = [input().split(' ') for i in range(n)]

div = True
for q in qs:
    if q[0] == '1':
        div = not div
    if q[0] == '2':
        if q[1] == '1':
            if div:
                s = q[2] + s
            else:
                s = s + q[2]
        if q[1] == '2':
            if div:
                s = s + q[2]
            else:
                s = q[2] + s

if div:
    print(s)
else:
    s = ''.join(list(reversed(s)))
    print(s)


Fixed submission:
from collections import deque

s = input()
n = int(input())
ans = deque(s)

div = True
for i in range(n):
    q = input().split(' ')
    if q[0] == '1':
        div = not div
    elif (q[1] == '1' and div) or (q[1] == '2' and not div):
        ans.appendleft(q[2])
    else:
        ans.append(q[2])

if div:
    print(''.join(ans))
else:
    print(''.join(reversed(ans)))