str = gets.chomp
com = gets.to_i
com.times do
  state = gets.split(' ')
  s1 = state[1].delete('?\"').to_i
  s2 = state[2].delete('?\"').to_i
  case state[0]
    when "print"
      puts str[s1..s2]
    when "reverse"
      str[s1..s2] = str[s1..s2].reverse
    when "replace"
      str[s1..s2] = state[3]
  end
end