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