str = gets.chomp
gets.to_i.times do
    order = gets.chomp.split
    s = order[1].to_i
    e = order[2].to_i
    temp = ""
    if order[0] == "replace" then
        if s > 0 then
            temp += str[0, s]
        end
        temp += order[3]
        if e < str.size-1 then
            temp += str[e+1..str.size-1]
        end
        elsif order[0] == "print" then
        puts str[s..e]
    else
        if s > 0 then
            temp += str[0, s]
        end
        temp += str[s..e].reverse
        if e < str.size-1 then
            temp += str[e+1..str.size-1]
        end
    end
    if order != "print" then
        str = temp
    end
end