str = gets.chomp
n = gets.to_i
n.times{
    order,a,b,rep = gets.split(" ")
    a = a.to_i
    b = b.to_i
    
    case order
    when "print"
        puts str[a..b]
    when "replace"
        str = str.gsub(/#{str[a..b]}/,rep)
    when "reverse"
        str = str.gsub(/#{str[a..b]}/,str[a..b].reverse)     
    end
}