      PROGRAM piyo
      IMPLICIT NONE
      character(2*(10**5)) :: s,a,p,buffer
      character(1) :: c
      integer(16) :: sLen,aLen,pLen,q,i,f,t
      character(5) :: in(2*(10**5))
      logical :: inv = .true.
      
      read*,s
      sLen = len_trim(s)
      read*,q
      aLen = 0
      pLen = 0
      
      do i = 1,q
        read'(a5)',in(i)
      end do
      
      
      do i = 1,q
        
        if( in(i)(1:1)=='1' )then
          inv = .not.(inv)
        else
          if( in(i)(3:3)=='1' )then
            if( inv )then
              aLen = aLen + 1
              a(aLen:aLen) = in(i)(5:5)
            else
              pLen = pLen + 1
              p(pLen:pLen) = in(i)(5:5)
            end if
          else
            if( inv )then
              pLen = pLen + 1
              p(pLen:pLen) = in(i)(5:5)
            else
              aLen = aLen + 1
              a(aLen:aLen) = in(i)(5:5)
            end if
          end if
        end if
        
      end do
      
      
      if( inv )then
      
        buffer(1:aLen) = a(1:aLen)
        do i = 1,aLen
          a(aLen-i+1:aLen-i+1) = buffer(i:i)
        end do
        
        print*,a(1:aLen)//s(1:sLen)//p(1:pLen)
      else
        buffer(1:sLen) = s(1:sLen)
        do i = 1,sLen
          s(sLen-i+1:sLen-i+1) = buffer(i:i)
        end do
        
        buffer(1:pLen) = p(1:pLen)
        do i = 1,pLen
          p(pLen-i+1:pLen-i+1) = buffer(i:i)
        end do
        print*,p(1:pLen)//s(1:sLen)//a(1:aLen)
      end if
      
      END PROGRAM