program main
      implicit none
      integer(4) :: q, i, j, length, frlen, enlen
      character(10000000) :: s
      character(5) ::inp(2*10**5)
      character(2*10**5) :: fr, en, buff
      logical :: flag = .true.

      read *, s
      read *, q
      do i = 1, q
        read '(a5)', inp(i)
      end do
      length = len(trim(s))

      frlen = 0
      enlen = 0
      do i = 1, q
        if ( inp(i)(1:1) == '1' ) then
          if ( flag ) then
            flag = .false.
          else
            flag = .true.
          end if
        else if ( inp(i)(1:1) == '2' ) then
          if ( inp(i)(3:3) == '1' ) then
            if ( flag ) then
               frlen = frlen + 1
               fr(frlen:frlen) = inp(i)(5:5)
            else
               enlen = enlen + 1
               en(enlen:enlen) = inp(i)(5:5)
            end if
          else
            if ( flag ) then
               enlen = enlen + 1
               en(enlen:enlen) = inp(i)(5:5)
            else
               frlen = frlen + 1
               fr(frlen:frlen) = inp(i)(5:5)
            end if
          end if
        end if
      end do

      if ( flag ) then
        buff = fr
        do i = 1, frlen
          fr(frlen-i+1:frlen-i+1) = buff(i:i) 
        end do
        print *, fr(1:frlen)//s(1:length)//en(1:enlen)
      else
        buff = en
        do i = 1, enlen
          en(enlen-i+1:enlen-i+1) = buff(i:i) 
        end do
        buff = s
        do i = 1, length
          s(length-i+1:length-i+1) = buff(i:i) 
        end do
        print *, en(1:enlen)//s(1:length)//fr(1:frlen)
      end if

end program main

