S = eval(input())

Q = int(eval(input()))

pre, suf = '', ''

rev = False

for _ in range(Q):

    query = input().split()

    if query[0] == '1':

        rev ^= 1

    else:

        f, c = query[1:]

        if (f == '1' and not rev) or (f == '2' and rev): pre = c + pre

        else: suf = suf + c

print((pre + S + suf if not rev else (pre + S + suf)[::-1]))
S = eval(input())

Q = int(eval(input()))

pre_rev, suf = '', ''

rev = False

for _ in range(Q):

    query = input().split()

    if query[0] == '1':

        rev ^= 1

    else:

        f, c = query[1:]

        if (f == '1' and not rev) or (f == '2' and rev): pre_rev = pre_rev + c

        else: suf = suf + c

print((pre_rev[::-1] + S + suf if not rev else (S + suf)[::-1] + pre_rev))
S = eval(input())
Q = int(eval(input()))
pre, suf = "", ""
rev = False
for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        rev ^= 1
    else:
        f, c = query[1:]
        if (f == "1" and not rev) or (f == "2" and rev):
            pre = c + pre
        else:
            suf = suf + c
print((pre + S + suf if not rev else (pre + S + suf)[::-1]))

S = eval(input())
Q = int(eval(input()))
pre_rev, suf = "", ""
rev = False
for _ in range(Q):
    query = input().split()
    if query[0] == "1":
        rev ^= 1
    else:
        f, c = query[1:]
        if (f == "1" and not rev) or (f == "2" and rev):
            pre_rev = pre_rev + c
        else:
            suf = suf + c
print((pre_rev[::-1] + S + suf if not rev else (S + suf)[::-1] + pre_rev))

-pre, suf = "", "" +pre_rev, suf = "", "" -            pre = c + pre +            pre_rev = pre_rev + c -print((pre + S + suf if not rev else (pre + S + suf)[::-1])) +print((pre_rev[::-1] + S + suf if not rev else (S + suf)[::-1] + pre_rev))