s=eval(input())

q=int(eval(input()))

que=[]

count=0

left=[]

right=[]

for i in range(q):

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

  if qu[0]=="1":

    count+=1

  que.append(qu)

han=0

for i in range(q):

  if que[i][0]=="1":

    han+=1

  else:

    if que[i][1]=="1":  

      if (count-han)%2==0:

        left.append(que[i][2])

      else:

        right.append(que[i][2])

    elif que[i][1]=="2":  

      if (count-han)%2==0:

        right.append(que[i][2])

      else:

        left.append(que[i][2])

ls="".join(left[::-1])

rs="".join(right)

if count%2==0:

  print((ls+s+rs))

else:

  print((ls+s[::-1]+rs))
s=eval(input())

q=int(eval(input()))

que=[list(map(str,input().split())) for i in range(q)]

count=0

for i in que:

  if i[0]=="1":

    count+=1

ans=[[],[]]

ak=count

for i in que:

  if i[0]=="1":

    count-=1

  else:

    if i[1]=="1":

      ans[count%2].append(i[2])

    else:

      ans[(count+1)%2].append(i[2])

if ak%2==0:

  print(("".join(reversed(ans[0]))+s+"".join(ans[1])))

else:

  print(("".join(reversed(ans[0]))+"".join(reversed(list(s)))+"".join(ans[1])))
s = eval(input())
q = int(eval(input()))
que = []
count = 0
left = []
right = []
for i in range(q):
    qu = list(map(str, input().split()))
    if qu[0] == "1":
        count += 1
    que.append(qu)
han = 0
for i in range(q):
    if que[i][0] == "1":
        han += 1
    else:
        if que[i][1] == "1":
            if (count - han) % 2 == 0:
                left.append(que[i][2])
            else:
                right.append(que[i][2])
        elif que[i][1] == "2":
            if (count - han) % 2 == 0:
                right.append(que[i][2])
            else:
                left.append(que[i][2])
ls = "".join(left[::-1])
rs = "".join(right)
if count % 2 == 0:
    print((ls + s + rs))
else:
    print((ls + s[::-1] + rs))

s = eval(input())
q = int(eval(input()))
que = [list(map(str, input().split())) for i in range(q)]
count = 0
for i in que:
    if i[0] == "1":
        count += 1
ans = [[], []]
ak = count
for i in que:
    if i[0] == "1":
        count -= 1
    else:
        if i[1] == "1":
            ans[count % 2].append(i[2])
        else:
            ans[(count + 1) % 2].append(i[2])
if ak % 2 == 0:
    print(("".join(reversed(ans[0])) + s + "".join(ans[1])))
else:
    print(("".join(reversed(ans[0])) + "".join(reversed(list(s))) + "".join(ans[1])))

-que = [] +que = [list(map(str, input().split())) for i in range(q)] -left = [] -right = [] -for i in range(q): -    qu = list(map(str, input().split())) -    if qu[0] == "1": +for i in que: +    if i[0] == "1": -    que.append(qu) -han = 0 -for i in range(q): -    if que[i][0] == "1": -        han += 1 +ans = [[], []] +ak = count +for i in que: +    if i[0] == "1": +        count -= 1 -        if que[i][1] == "1": -            if (count - han) % 2 == 0: -                left.append(que[i][2]) -            else: -                right.append(que[i][2]) -        elif que[i][1] == "2": -            if (count - han) % 2 == 0: -                right.append(que[i][2]) -            else: -                left.append(que[i][2]) -ls = "".join(left[::-1]) -rs = "".join(right) -if count % 2 == 0: -    print((ls + s + rs)) +        if i[1] == "1": +            ans[count % 2].append(i[2]) +        else: +            ans[(count + 1) % 2].append(i[2]) +if ak % 2 == 0: +    print(("".join(reversed(ans[0])) + s + "".join(ans[1]))) -    print((ls + s[::-1] + rs)) +    print(("".join(reversed(ans[0])) + "".join(reversed(list(s))) + "".join(ans[1])))