str = gets.chomp
gets.to_i.times do
  n = gets.chomp.split
  f = n[1].to_i
  l = n[2].to_i
  case n[0]
  when 'replace'
    str[f..l] = n[3]
  when 'reverse'
    str[f..l] = str[f..l].reverse
  when 'print'
    puts str[f..l]
  end
end