=begin
    abcde
    3
    replace 1 3 xyz
    reverse 0 2
    print 1 4
=end

s = gets.chomp
n = gets.to_i

def split(s, p1, p2)
    x = s[0, p1]
    y = s[p1..p2]
    z = s[p2 + 1, s.size]
    return x, y, z
end

n.times do |i|
    a = gets.split(" ")
    
    if a[0].eql?("print") then
        print s[a[1].to_i..a[2].to_i], "\n"
    elsif a[0].eql?("reverse") then
        x, y, z = split(s, a[1].to_i, a[2].to_i)
        s = x + y.reverse + z
    elsif a[0].eql?("replace") then
        x, y, z = split(s, a[1].to_i, a[2].to_i)
        s = x + a[3] + z
    end
end

