s = str(eval(input()))

q = int(eval(input()))

inv = False

head = ''

tail = ''



for i in range(q):

    a = eval(input())

    if a == '1':

        inv = not inv

        continue

    a = a.split()

    if (a[1] == '1')^inv:

        head = a[2] + head

    else:

        tail += a[2]

s = head + s + tail

if inv:

    print((s[::-1]))

else:

    print(s)
s = str(eval(input()))

q = int(eval(input()))

inv = False

head = ''

tail = ''

 

for i in range(q):

    a = eval(input())

    if a == '1':

        inv = not inv

        continue

    a = a.split()

    if (a[1] == '1')^inv:

        head += a[2]

    else:

        tail += a[2]

#s = head + s + tail

if inv:

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

else:

    print((head[::-1]+s+tail))
s = str(eval(input()))
q = int(eval(input()))
inv = False
head = ""
tail = ""
for i in range(q):
    a = eval(input())
    if a == "1":
        inv = not inv
        continue
    a = a.split()
    if (a[1] == "1") ^ inv:
        head = a[2] + head
    else:
        tail += a[2]
s = head + s + tail
if inv:
    print((s[::-1]))
else:
    print(s)

s = str(eval(input()))
q = int(eval(input()))
inv = False
head = ""
tail = ""
for i in range(q):
    a = eval(input())
    if a == "1":
        inv = not inv
        continue
    a = a.split()
    if (a[1] == "1") ^ inv:
        head += a[2]
    else:
        tail += a[2]
# s = head + s + tail
if inv:
    print((tail[::-1] + s[::-1] + head))
else:
    print((head[::-1] + s + tail))

-        head = a[2] + head +        head += a[2] -s = head + s + tail +# s = head + s + tail -    print((s[::-1])) +    print((tail[::-1] + s[::-1] + head)) -    print(s) +    print((head[::-1] + s + tail))