str = gets.chomp
opnum = gets.to_i

opnum.times do
    opary = gets.chomp.split
    a, b = opary[1].to_i, opary[2].to_i
    case opary[0]
    when "print"
        for i in a..b
            print str[i]
        end
        puts ""
    when "reverse"
        str = str[0...a] + str[a..b].reverse + str[(b + 1)...str.size]
    when "replace"
        str[a..b] = opary[3]
    end
end