# ABC158 D

from collections import deque

s=eval(input())

q=int(eval(input()))

l=[]



for i in range(q):

    l.append(list(map(str,input().split())))



cnt=0

front_str=''

end_str=''



t_str=deque(s)

front_str=deque(front_str)

end_str=deque(end_str)



for ll in l:

    if ll[0]=='1':

        cnt+=1

    elif ll[0]=='2':

        if cnt%2==0:

            if ll[1]=='1':

                front_str.appendleft(ll[2])

            elif ll[1]=='2':

                end_str.append(ll[2])

        elif cnt%2==1:

            if ll[1]=='1':

                end_str.append(ll[2])

            elif ll[1]=='2':

                front_str.appendleft(ll[2])

ans=list(front_str)+list(t_str)+list(end_str)



if cnt%2==0:

    ans=''.join(ans)

else:

    ans=ans[::-1]

    ans=''.join(ans)

print(ans)



s=eval(input())

q=int(eval(input()))

m=0

from collections import deque

s=deque(s)

for i in range(q):

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

  if l[0]=="1":

    m+=1

    m%=2

  else:

    if m==0:

      if l[1]=="1":

        s.appendleft(l[2])

      else:

        s.append(l[2])

    else:

      if l[1]=="1":

        s.append(l[2])

      else:

        s.appendleft(l[2])

s=list(s)

if m==1:

  s=s[::-1]

print(("".join(s)))



# ABC158 D
from collections import deque

s = eval(input())
q = int(eval(input()))
l = []
for i in range(q):
    l.append(list(map(str, input().split())))
cnt = 0
front_str = ""
end_str = ""
t_str = deque(s)
front_str = deque(front_str)
end_str = deque(end_str)
for ll in l:
    if ll[0] == "1":
        cnt += 1
    elif ll[0] == "2":
        if cnt % 2 == 0:
            if ll[1] == "1":
                front_str.appendleft(ll[2])
            elif ll[1] == "2":
                end_str.append(ll[2])
        elif cnt % 2 == 1:
            if ll[1] == "1":
                end_str.append(ll[2])
            elif ll[1] == "2":
                front_str.appendleft(ll[2])
ans = list(front_str) + list(t_str) + list(end_str)
if cnt % 2 == 0:
    ans = "".join(ans)
else:
    ans = ans[::-1]
    ans = "".join(ans)
print(ans)

s = eval(input())
q = int(eval(input()))
m = 0
from collections import deque

s = deque(s)
for i in range(q):
    l = list(map(str, input().split()))
    if l[0] == "1":
        m += 1
        m %= 2
    else:
        if m == 0:
            if l[1] == "1":
                s.appendleft(l[2])
            else:
                s.append(l[2])
        else:
            if l[1] == "1":
                s.append(l[2])
            else:
                s.appendleft(l[2])
s = list(s)
if m == 1:
    s = s[::-1]
print(("".join(s)))

-# ABC158 D +s = eval(input()) +q = int(eval(input())) +m = 0 -s = eval(input()) -q = int(eval(input())) -l = [] +s = deque(s) -    l.append(list(map(str, input().split()))) -cnt = 0 -front_str = "" -end_str = "" -t_str = deque(s) -front_str = deque(front_str) -end_str = deque(end_str) -for ll in l: -    if ll[0] == "1": -        cnt += 1 -    elif ll[0] == "2": -        if cnt % 2 == 0: -            if ll[1] == "1": -                front_str.appendleft(ll[2]) -            elif ll[1] == "2": -                end_str.append(ll[2]) -        elif cnt % 2 == 1: -            if ll[1] == "1": -                end_str.append(ll[2]) -            elif ll[1] == "2": -                front_str.appendleft(ll[2]) -ans = list(front_str) + list(t_str) + list(end_str) -if cnt % 2 == 0: -    ans = "".join(ans) -else: -    ans = ans[::-1] -    ans = "".join(ans) -print(ans) +    l = list(map(str, input().split())) +    if l[0] == "1": +        m += 1 +        m %= 2 +    else: +        if m == 0: +            if l[1] == "1": +                s.appendleft(l[2]) +            else: +                s.append(l[2]) +        else: +            if l[1] == "1": +                s.append(l[2]) +            else: +                s.appendleft(l[2]) +s = list(s) +if m == 1: +    s = s[::-1] +print(("".join(s)))