def Print(str, d)
    a, b = d[1].to_i, d[2].to_i
    puts "#{str[a..b]}"
end

def Reverse(str, d)
    a, b = d[1].to_i, d[2].to_i
    str[a..b] = str[a..b].reverse
    #puts "rev : #{str}"
    str
end

def Replace(str, d)
    a, b = d[1].to_i, d[2].to_i
    str[a..b] = d[3]
    #puts "rep : #{str}"
    str
end

str = gets.chomp
gets.to_i.times {
    d = gets.chomp.split(" ")
    
    case d[0]
    when "print"
        Print(str, d)
    when "replace"
        str = Replace(str, d)
    when "reverse"
        str = Reverse(str, d)
    end
}