str = gets.chomp
q = gets.to_i

q.times do
  cmd, a, b, q = gets.chomp.split
  a, b = [a, b].map(&:to_i)
  case cmd
  when 'print'
    puts str[a, b - a + 1]
  when 'reverse'
    str[a, b - a + 1] = str[a, b - a + 1].reverse
  when 'replace'
    str[a, b - a + 1] = q
  end
end