str = gets.chomp
q = gets.chomp.to_i
q.times {
    order = gets.chomp.split(" ")
    if order[0] == "print"
        print(str[order[1].to_i..order[2].to_i],"\n")
    elsif order[0] == "reverse"
        str[order[1].to_i..order[2].to_i] = str[order[1].to_i..order[2].to_i].reverse
    elsif order[0] == "replace"
        str[order[1].to_i..order[2].to_i] = order[3]
    end
}