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

s = deque(input())

q = int(input())

for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        s.reverse()
    else:
        if A[1] == '1':
            s.appendleft(A[2])
        else:
            s.append(A[2])
print("".join(list(s)))

Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

s = deque(input())

q = int(input())

for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        s.reverse()
    else:
        if A[1] == '1':
            s.appendleft(A[2])
        else:
            s.append(A[2])
print("".join(s))

Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):

from collections import deque
s = deque(input())
q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        s.reverse()
    else:
        if (A[1] == '1'):
            s.appendleft(A[2])
        else:
            s.append(A[2])
print("".join(s))

Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

Buggy python submission (verdict: Time Limit Exceeded):

from collections import deque
s = deque(input())
q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        s.reverse()
    else:
        if (A[1] == '1'):
            s.appendleft(A[2])
        else:
            s.append(A[2])
print("".join(s))


Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] != '1' and r % 2 != 0):
            b = A[2] + b
        else:
            c = c + A[2]
# s = b + s + c
if r % 2 == 0:
    print(b+s+c)
else:
    # print(s[::-1])
    print(c[::-1] + s[::-1] + b[::-1])


Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] != '1' and r % 2 != 0):
            b = A[2] + b
        else:
            c = c + A[2]
s = b + s + c
if r % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

q = int(input())
r = 0
b = ""
c = ""
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] != '1' and r % 2 != 0):
            # s = A[2] + s
            b = A[2] + b
        else:
            # s = s+ A[2]
            c = c + A[2]
s = b + s + c
if r % 2 == 0:
    print(s)
else:
    print(s[::-1])


Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

q = int(input())
r = 0
t = 0
for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        r += 1
    else:
        if A[1] == '1':
            if r % 2 == 0:
                s = A[2] + s
            else:
                s = s + A[2]
        else:
            if r % 2 == 0:
                s = s + A[2]
            else:
                s = A[2] + s
if r % 2 == 0:
    print(s)
else:
    print(s[::-1])

Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))

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

q = int(input())

for i in range(q):
    A = list(input().split())
    if A[0] == '1':
        s = s[::-1]
    else:
        if A[1] == '1':
            s = A[2] + s
        else:
            s = s + A[2]
print(s)

Fixed submission:
from collections import deque

s = deque(input())

q = int(input())
r = 0
for _ in range(q):
    A = list(input().split())
    if A[0] == '1':
        r = (r + 1)%2
    else:
        if (A[1] == '1' and r % 2 == 0) or (A[1] == '2' and r % 2 == 1):
            s.appendleft(A[2])
        else:
            s.append(A[2])

if r == 1:
    s.reverse()
print("".join(s))