S = list(eval(input()))

Q = int(eval(input()))

a = 0

A = []

B = []

for i in range(Q):

  q = list(input().split())

  q[0] = int(q[0])

  if q[0] == 1:

    if a == 0:

      a = 1

    else:

      a = 0

  else:

    q[1] = int(q[1])

    if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):

      B.append(q[2])

    else:

      A.append(q[2])

B = B[::-1]

ans = B + S + A

if a == 1:

  ans = ans[::-1]

ans = ''.join(ans)

print(ans)
S = list(eval(input()))

Q = int(eval(input()))

A = []

a = 0

for i in range(Q):

  q = list(input().split())

  if q[0] == '1':

    a += 1

  else:

    if (q[1] == '1' and a % 2 == 0) or (q[1] == '2' and a % 2 == 1):

      A.append(q[2])

    else:

      S.append(q[2])

A = A[::-1]

S = A + S

if a % 2 == 1:

  S = S[::-1]

ans = ''.join(S)

print(ans)

      

  
S = list(eval(input()))
Q = int(eval(input()))
a = 0
A = []
B = []
for i in range(Q):
    q = list(input().split())
    q[0] = int(q[0])
    if q[0] == 1:
        if a == 0:
            a = 1
        else:
            a = 0
    else:
        q[1] = int(q[1])
        if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1):
            B.append(q[2])
        else:
            A.append(q[2])
B = B[::-1]
ans = B + S + A
if a == 1:
    ans = ans[::-1]
ans = "".join(ans)
print(ans)

S = list(eval(input()))
Q = int(eval(input()))
A = []
a = 0
for i in range(Q):
    q = list(input().split())
    if q[0] == "1":
        a += 1
    else:
        if (q[1] == "1" and a % 2 == 0) or (q[1] == "2" and a % 2 == 1):
            A.append(q[2])
        else:
            S.append(q[2])
A = A[::-1]
S = A + S
if a % 2 == 1:
    S = S[::-1]
ans = "".join(S)
print(ans)

+A = [] -A = [] -B = [] -    q[0] = int(q[0]) -    if q[0] == 1: -        if a == 0: -            a = 1 +    if q[0] == "1": +        a += 1 +    else: +        if (q[1] == "1" and a % 2 == 0) or (q[1] == "2" and a % 2 == 1): +            A.append(q[2]) -            a = 0 -    else: -        q[1] = int(q[1]) -        if (q[1] == 1 and a == 0) or (q[1] == 2 and a == 1): -            B.append(q[2]) -        else: -            A.append(q[2]) -B = B[::-1] -ans = B + S + A -if a == 1: -    ans = ans[::-1] -ans = "".join(ans) +            S.append(q[2]) +A = A[::-1] +S = A + S +if a % 2 == 1: +    S = S[::-1] +ans = "".join(S)