program main
  implicit none
  character(len=300000) :: S(0:1)
  character(len=1) :: c
  integer :: i,Q,j,j2,N, ii
  integer :: t, f
  read(*,*) S(0)
  read(*,*) Q
  N = len_trim(S(0))
  do i = 1, Q
     read(*,*) t
     j = mod(i,2)
     if ( j == 0 ) then
        j2 = 1
     else
        j2 = 0
     end if
     if (t == 1) then
        backspace(5)
        read(*,*) t
        do ii = 1,N
           S(j)(ii:ii) = S(j2)(N-ii+1:N-ii+1)
        end do
     else
        backspace(5)
        read(*,*) t, f, C
        if ( f == 1 ) then
           S(j)(1:1) = C
           S(j)(2:N+1) = S(j2)(1:N)
        else
           S(j)(1:N) = S(j2)(1:N)
           S(j)(N+1:N+1) = C
        end if
        N = N + 1
     end if
  end do
  write(*,'(a)') trim(S(j))
end program main
