str = gets.chomp
gets.chomp.to_i.times do
  command, s, e, replace_str = gets.chomp.split
  s, e = s.to_i, e.to_i
  if command == "replace"
    str[s..e] = replace_str
  elsif command == "reverse"
    str[s..e] = str[s..e].reverse
  else
    puts str[s..e]
  end
end
