s = gets.chomp.split("")
gets.chomp.to_i.times do
  c = gets.chomp.split
  c[1] = c[1].to_i
  c[2] = c[2].to_i
  case c[0]
  when "print"
    (c[1]..c[2]).each do |i|
      print s[i]
    end
    puts
  when "reverse"
    r = []
    (c[1]..c[2]).each do |i|
      r.push(s[i])
    end
    r.reverse!
    (c[1]..c[2]).each do |i|
      s[i] = r[0]
      r.shift
    end
  when "replace"
    r = c[3].split("")
    (c[1]..c[2]).each do |i|
      s[i] = r[0]
      r.shift
    end
  end
end