s=eval(input())

q_=int(eval(input()))

q=[eval(input()) for _ in range(q_)]

reverse=False

pre=[]

fin=[]

for qi in q:

    if qi[0]=='1':

        reverse=not reverse

    elif qi[2]=='1' and reverse==False:

        pre.append(qi[4])

    elif qi[2]=='1' and reverse==True:

        fin.append(qi[4])

    elif qi[2]=='2' and reverse==False:

        fin.append(qi[4])

    elif qi[2]=='2' and reverse==True:

        pre.append(qi[4])

if reverse==False:

    print((''.join([p for p in pre[::-1]])+s+''.join(fin)))

else:

    print((''.join([f for f in fin[::-1]])+''.join([si for si in list(s)[::-1]])+''.join(pre)))
s=list(eval(input()))

q=int(eval(input()))

rv=False

right=[]

left=[]

for _ in range(q):

  query=eval(input())

  if query[0]=='1':

    rv=not rv

  else:

    _,f,c=query.split()

    if f=='1' and rv==False:

      left.append(c)

    elif f=='1' and rv==True:

      right.append(c)

    elif f=='2' and rv==False:

      right.append(c)

    elif f=='2' and rv==True:

      left.append(c)

if not rv:

  left.reverse()

  print((''.join(left)+''.join(s)+''.join(right)))

else:

  right.reverse()

  s.reverse()

  print((''.join(right)+''.join(s)+''.join(left)))

s = eval(input())
q_ = int(eval(input()))
q = [eval(input()) for _ in range(q_)]
reverse = False
pre = []
fin = []
for qi in q:
    if qi[0] == "1":
        reverse = not reverse
    elif qi[2] == "1" and reverse == False:
        pre.append(qi[4])
    elif qi[2] == "1" and reverse == True:
        fin.append(qi[4])
    elif qi[2] == "2" and reverse == False:
        fin.append(qi[4])
    elif qi[2] == "2" and reverse == True:
        pre.append(qi[4])
if reverse == False:
    print(("".join([p for p in pre[::-1]]) + s + "".join(fin)))
else:
    print(
        (
            "".join([f for f in fin[::-1]])
            + "".join([si for si in list(s)[::-1]])
            + "".join(pre)
        )
    )

s = list(eval(input()))
q = int(eval(input()))
rv = False
right = []
left = []
for _ in range(q):
    query = eval(input())
    if query[0] == "1":
        rv = not rv
    else:
        _, f, c = query.split()
        if f == "1" and rv == False:
            left.append(c)
        elif f == "1" and rv == True:
            right.append(c)
        elif f == "2" and rv == False:
            right.append(c)
        elif f == "2" and rv == True:
            left.append(c)
if not rv:
    left.reverse()
    print(("".join(left) + "".join(s) + "".join(right)))
else:
    right.reverse()
    s.reverse()
    print(("".join(right) + "".join(s) + "".join(left)))

-s = eval(input()) -q_ = int(eval(input())) -q = [eval(input()) for _ in range(q_)] -reverse = False -pre = [] -fin = [] -for qi in q: -    if qi[0] == "1": -        reverse = not reverse -    elif qi[2] == "1" and reverse == False: -        pre.append(qi[4]) -    elif qi[2] == "1" and reverse == True: -        fin.append(qi[4]) -    elif qi[2] == "2" and reverse == False: -        fin.append(qi[4]) -    elif qi[2] == "2" and reverse == True: -        pre.append(qi[4]) -if reverse == False: -    print(("".join([p for p in pre[::-1]]) + s + "".join(fin))) +s = list(eval(input())) +q = int(eval(input())) +rv = False +right = [] +left = [] +for _ in range(q): +    query = eval(input()) +    if query[0] == "1": +        rv = not rv +    else: +        _, f, c = query.split() +        if f == "1" and rv == False: +            left.append(c) +        elif f == "1" and rv == True: +            right.append(c) +        elif f == "2" and rv == False: +            right.append(c) +        elif f == "2" and rv == True: +            left.append(c) +if not rv: +    left.reverse() +    print(("".join(left) + "".join(s) + "".join(right))) -    print( -        ( -            "".join([f for f in fin[::-1]]) -            + "".join([si for si in list(s)[::-1]]) -            + "".join(pre) -        ) -    ) +    right.reverse() +    s.reverse() +    print(("".join(right) + "".join(s) + "".join(left)))