str = gets.chomp
gets.to_i.times do
    q = gets.chomp.split
    a = n[1].to_i
    b = n[2].to_i
    case n[0]
    when 'replace'
        str[a..b] = n[3]
    when 'reverse'
        str[a..b] = str[a..b].reverse
    when 'print'
        puts str[a..b]
    end
end