import collections



s=eval(input())

t=collections.deque()

t.append(s)

q=int(eval(input()))

flag=False

for _ in range(q):

  query=list(map(str,input().split()))

  if query[0]=='1':

    if flag==False:

      flag=True

    else:

      flag=False

  elif query[0]=='2':

    if query[1]=='1':

      if flag==False:

        t.appendleft(query[2])

      else:

        t.append(query[2])

    else:

      if flag==False:

        t.append(query[2])

      else:

        t.appendleft(query[2])

t=''.join(map(str,t))

if flag==False:

  print(t)

else:

  print((t[::-1]))
s=eval(input())

q=int(eval(input()))

head=[]

tail=[]

rev=False

for _ in range(q):

  tmp=list(input().split())

  if tmp[0]=='1':

    if rev==False:

      rev=True

    else:

      rev=False

  if tmp[0]=='2':

    if rev==False:

      if tmp[1]=='1':

        head.append(tmp[2])

      if tmp[1]=='2':

        tail.append(tmp[2])

    if rev==True:

      if tmp[1]=='1':

        tail.append(tmp[2])

      if tmp[1]=='2':

        head.append(tmp[2])

head=''.join(map(str,head))

tail=''.join(map(str,tail))

ans=head[::-1]+s+tail

if rev==True:

  ans=ans[::-1]

print(ans)
import collections

s = eval(input())
t = collections.deque()
t.append(s)
q = int(eval(input()))
flag = False
for _ in range(q):
    query = list(map(str, input().split()))
    if query[0] == "1":
        if flag == False:
            flag = True
        else:
            flag = False
    elif query[0] == "2":
        if query[1] == "1":
            if flag == False:
                t.appendleft(query[2])
            else:
                t.append(query[2])
        else:
            if flag == False:
                t.append(query[2])
            else:
                t.appendleft(query[2])
t = "".join(map(str, t))
if flag == False:
    print(t)
else:
    print((t[::-1]))

s = eval(input())
q = int(eval(input()))
head = []
tail = []
rev = False
for _ in range(q):
    tmp = list(input().split())
    if tmp[0] == "1":
        if rev == False:
            rev = True
        else:
            rev = False
    if tmp[0] == "2":
        if rev == False:
            if tmp[1] == "1":
                head.append(tmp[2])
            if tmp[1] == "2":
                tail.append(tmp[2])
        if rev == True:
            if tmp[1] == "1":
                tail.append(tmp[2])
            if tmp[1] == "2":
                head.append(tmp[2])
head = "".join(map(str, head))
tail = "".join(map(str, tail))
ans = head[::-1] + s + tail
if rev == True:
    ans = ans[::-1]
print(ans)

-import collections - -t = collections.deque() -t.append(s) -flag = False +head = [] +tail = [] +rev = False -    query = list(map(str, input().split())) -    if query[0] == "1": -        if flag == False: -            flag = True +    tmp = list(input().split()) +    if tmp[0] == "1": +        if rev == False: +            rev = True -            flag = False -    elif query[0] == "2": -        if query[1] == "1": -            if flag == False: -                t.appendleft(query[2]) -            else: -                t.append(query[2]) -        else: -            if flag == False: -                t.append(query[2]) -            else: -                t.appendleft(query[2]) -t = "".join(map(str, t)) -if flag == False: -    print(t) -else: -    print((t[::-1])) +            rev = False +    if tmp[0] == "2": +        if rev == False: +            if tmp[1] == "1": +                head.append(tmp[2]) +            if tmp[1] == "2": +                tail.append(tmp[2]) +        if rev == True: +            if tmp[1] == "1": +                tail.append(tmp[2]) +            if tmp[1] == "2": +                head.append(tmp[2]) +head = "".join(map(str, head)) +tail = "".join(map(str, tail)) +ans = head[::-1] + s + tail +if rev == True: +    ans = ans[::-1] +print(ans)