s = gets.chomp
q = gets.to_i
q.times do |i|
    t = gets.split
    order = t[0]
    a = t[1].to_i
    b = t[2].to_i
    case order
    when 'print'
        puts s[a..b]
    when 'reverse'
        first = a == 0 ? '' : s[0..a-1]
        middle = s[a..b].reverse
        final = b == s.length-1 ? '' : s[b+1..-1]
        s = first + middle + final
    when 'replace'
        word = t[3]
        first = a == 0 ? '' : s[0..a-1]
        middle = word
        final = b == s.length-1 ? '' : s[b+1..-1]
        s = first + middle + final
    end
end
