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 += li[2]

        else:

            tail += li[2]



if cnt % 2 != 0:

    s = s[::-1]



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

print(*ans , sep='')

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 = 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 += li[2]
        else:
            tail += li[2]
if cnt % 2 != 0:
    s = s[::-1]
ans = head[::-1] + s + tail
print(*ans, sep="")

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="")

-            head += li[2] +            head.append(li[2]) -            tail += li[2] +            tail.append(li[2])