program ABC158_D
  character(300000)::S,R
  integer::Q,T,F
  character(5)::query
  character(1)::C
  read(5,*)S
  read(5,*)Q
  N=len_trim(S)
  do I=1,Q
     read(5,'(A)')query
     if(query(1:1)=='1') then
        do J=1,N
           R(J:J)=S(N+1-J:N+1-J)
        end do
        S(1:N)=R(1:N)
     else
        read(query,*)T,F,C
        if(F==1) then
           do J=N,1,-1
              S(J+1:J+1)=S(J:J)
           end do
           S(1:1)=C
           N=N+1
        else
           S(N+1:N+1)=C
           N=N+1
        end if
     end if
  end do
  write(6,*)S(1:N)
end program ABC158_D