s = list(input())

n = int(input())

head = []

tail = []



cnt = 0

for _ in range(n):

    li = list(input().split())

    if li[0] == '1':

        head, tail = tail, head

        cnt += 1

    else:

        if li[1] == '1':

            head.append(li[2])

        else:

            tail.append(li[2])



if cnt % 2 != 0:

    s = s[::-1]



ans = head[::-1] + s + tail

print(*ans , sep='')

s = eval(input())

q = int(eval(input()))

head = ''

tail = ''

rev = 0



for _ in range(q):

    T = list(input().split())

    if T[0] == '1':

        head, tail = tail, head

        rev += 1

    else:

        if T[1] == '1':

            head += T[2]

        else:

            tail += T[2]



if rev%2 == 0:

    print((head[::-1]+s+tail))

else:

    print((head[::-1]+s[::-1]+tail))

s = list(input())
n = int(input())
head = []
tail = []
cnt = 0
for _ in range(n):
    li = list(input().split())
    if li[0] == "1":
        head, tail = tail, head
        cnt += 1
    else:
        if li[1] == "1":
            head.append(li[2])
        else:
            tail.append(li[2])
if cnt % 2 != 0:
    s = s[::-1]
ans = head[::-1] + s + tail
print(*ans, sep="")

s = eval(input())
q = int(eval(input()))
head = ""
tail = ""
rev = 0
for _ in range(q):
    T = list(input().split())
    if T[0] == "1":
        head, tail = tail, head
        rev += 1
    else:
        if T[1] == "1":
            head += T[2]
        else:
            tail += T[2]
if rev % 2 == 0:
    print((head[::-1] + s + tail))
else:
    print((head[::-1] + s[::-1] + tail))

-s = list(input()) -n = int(input()) -head = [] -tail = [] -cnt = 0 -for _ in range(n): -    li = list(input().split()) -    if li[0] == "1": +s = eval(input()) +q = int(eval(input())) +head = "" +tail = "" +rev = 0 +for _ in range(q): +    T = list(input().split()) +    if T[0] == "1": -        cnt += 1 +        rev += 1 -        if li[1] == "1": -            head.append(li[2]) +        if T[1] == "1": +            head += T[2] -            tail.append(li[2]) -if cnt % 2 != 0: -    s = s[::-1] -ans = head[::-1] + s + tail -print(*ans, sep="") +            tail += T[2] +if rev % 2 == 0: +    print((head[::-1] + s + tail)) +else: +    print((head[::-1] + s[::-1] + tail))