# 文字列の操作だけでできるか



S = eval(input())

Q = int(eval(input()))



T = 0

l = ""

r = ""

for i in range(Q):

    Query = list(input().split())

    if len(Query) == 1:

        # T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)

        T ^= 1

    elif T == 0:

        s = Query[2]

        if Query[1] == '1':

            #S = s + S

            l = s + l

        else:

            #S = S + s

            r = r + s

    else:

        s = Query[2]

        if Query[1] == '1':

            #S = S + s

            r = r + s

        else:

            #S = s + S

            l = s + l



S = l + S + r



if T == 1:

    S = S[::-1]



print(S)

# list の append だけで実装する



S = eval(input())

Q = int(eval(input()))



T = 0

l = []

r = []

for _ in range(Q):

    Query = list(input().split())

    if len(Query) == 1:

        T ^= 1

    elif T == 0:

        s = Query[2]

        if Query[1] == '1':

            l.append(s)

        else:

            r.append(s)

    else:

        s = Query[2]

        if Query[1] == '1':

            r.append(s)

        else:

            l.append(s)



if T == 1:

    r.reverse()

    ans = ''.join(r) + S[::-1] + ''.join(l)

else:

    l.reverse()

    ans = ''.join(l) + S + ''.join(r)



print(ans)

# 文字列の操作だけでできるか
S = eval(input())
Q = int(eval(input()))
T = 0
l = ""
r = ""
for i in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        # T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0)
        T ^= 1
    elif T == 0:
        s = Query[2]
        if Query[1] == "1":
            # S = s + S
            l = s + l
        else:
            # S = S + s
            r = r + s
    else:
        s = Query[2]
        if Query[1] == "1":
            # S = S + s
            r = r + s
        else:
            # S = s + S
            l = s + l
S = l + S + r
if T == 1:
    S = S[::-1]
print(S)

# list の append だけで実装する
S = eval(input())
Q = int(eval(input()))
T = 0
l = []
r = []
for _ in range(Q):
    Query = list(input().split())
    if len(Query) == 1:
        T ^= 1
    elif T == 0:
        s = Query[2]
        if Query[1] == "1":
            l.append(s)
        else:
            r.append(s)
    else:
        s = Query[2]
        if Query[1] == "1":
            r.append(s)
        else:
            l.append(s)
if T == 1:
    r.reverse()
    ans = "".join(r) + S[::-1] + "".join(l)
else:
    l.reverse()
    ans = "".join(l) + S + "".join(r)
print(ans)

-# 文字列の操作だけでできるか +# list の append だけで実装する -l = "" -r = "" -for i in range(Q): +l = [] +r = [] +for _ in range(Q): -        # T = T ^ 1 (排他的論理和; 0 XOR 1 = 1, 1 XOR 1 = 0) -            # S = s + S -            l = s + l +            l.append(s) -            # S = S + s -            r = r + s +            r.append(s) -            # S = S + s -            r = r + s +            r.append(s) -            # S = s + S -            l = s + l -S = l + S + r +            l.append(s) -    S = S[::-1] -print(S) +    r.reverse() +    ans = "".join(r) + S[::-1] + "".join(l) +else: +    l.reverse() +    ans = "".join(l) + S + "".join(r) +print(ans)