s = gets.chomp
gets.to_i.times do
  cmd = gets.split
  a = cmd[1].to_i
  b = cmd[2].to_i
  case cmd[0]
  when "print" then
    puts s[a..b]
  when "reverse" then
    s[a..b] = s[a..b].reverse
  when "replace" then
    s[a..b] = cmd[3]
  end
end
