program main
  implicit none
  integer :: q, i, p1, p2
  logical :: flipped
  character(100000) :: s
  character(900000) :: s2
  character(5) :: query
  read (*, *) s
  p1 = 400000
  p2 = 400000 + len_trim(s) - 1
  flipped = .false.
  s2(p1:p2) = s(:)
  read (*, *) q
  do i = 1, q
    read (*, "(a5)") query
    if (query(1:1) == "1") then
      flipped = (.not. flipped)
    else
      if (query(3:3) == "1" .neqv. flipped) then
        p1 = p1 - 1
        s2(p1:p1) = query(5:5)
      else
        p2 = p2 + 1
        s2(p2:p2) = query(5:5)
      end if
    end if
  end do
  if (flipped) call flip(s2(p1:p2), p2 - p1 + 1)
  write (*, "(a)") s2(p1:p2)
  contains
  subroutine flip(s, n)
    integer, intent(in) :: n
    character(n), intent(inout) :: s
    character(1) :: c
    integer :: i
    do i = 1, n / 2
      c = s(i:i)
      s(i:i) = s(n - i + 1:n - i + 1)
      s(n - i + 1:n - i + 1) = c
    end do
  end subroutine flip
end program main
