wordarr = gets.chomp.split("").map do |s| s.to_s end
time = gets.chomp.to_i
time.times do
    oparr = gets.chomp.split(" ").map do |s| s.to_s end
    if oparr[0] == "replace"
        wordarr[oparr[1].to_i..oparr[2].to_i] = oparr[3].split("")
    elsif oparr[0] == "reverse"
        wordarr[oparr[1].to_i..oparr[2].to_i] = wordarr[oparr[1].to_i..oparr[2].to_i].reverse
    elsif oparr[0] == "print"
        puts wordarr[oparr[1].to_i..oparr[2].to_i].join("")
    end
end