s=list(eval(input()))

q=int(eval(input()))

t1,t2=[],[]

cnt=0

for _ in range(q):

  t=list(input().split())

  if len(t)==1:

    cnt+=1

    t1,t2=t2,t1

  else:

    if int(t[1])==1:

      t1+=[t[2]]

    else:

      t2+=[t[2]]

if cnt%2==1:

  s=s[::-1]

u=t1[::-1]+s+t2

print((''.join(u)))
s=eval(input())

q=int(eval(input()))

cnt=0

a1,a2=[],[]

for _ in range(q):

  t=list(input().split())

  if t[0]=='1':

    cnt+=1

    a1,a2=a2,a1

  else:

    if t[1]=='1':

      a1.append(t[2])

    else:

      a2.append(t[2])

if cnt%2==1:

  s=s[::-1]

print((''.join(a1[::-1])+s+''.join(a2)))
s = list(eval(input()))
q = int(eval(input()))
t1, t2 = [], []
cnt = 0
for _ in range(q):
    t = list(input().split())
    if len(t) == 1:
        cnt += 1
        t1, t2 = t2, t1
    else:
        if int(t[1]) == 1:
            t1 += [t[2]]
        else:
            t2 += [t[2]]
if cnt % 2 == 1:
    s = s[::-1]
u = t1[::-1] + s + t2
print(("".join(u)))

s = eval(input())
q = int(eval(input()))
cnt = 0
a1, a2 = [], []
for _ in range(q):
    t = list(input().split())
    if t[0] == "1":
        cnt += 1
        a1, a2 = a2, a1
    else:
        if t[1] == "1":
            a1.append(t[2])
        else:
            a2.append(t[2])
if cnt % 2 == 1:
    s = s[::-1]
print(("".join(a1[::-1]) + s + "".join(a2)))

-s = list(eval(input())) +s = eval(input()) -t1, t2 = [], [] +a1, a2 = [], [] -    if len(t) == 1: +    if t[0] == "1": -        t1, t2 = t2, t1 +        a1, a2 = a2, a1 -        if int(t[1]) == 1: -            t1 += [t[2]] +        if t[1] == "1": +            a1.append(t[2]) -            t2 += [t[2]] +            a2.append(t[2]) -u = t1[::-1] + s + t2 -print(("".join(u))) +print(("".join(a1[::-1]) + s + "".join(a2)))