str = gets.to_s

q = gets.to_i

q.times do
  operation = gets.to_s.split
  a = operation[1].to_i
  b = operation[2].to_i

  case operation[0]
  when 'replace'
    _p = operation[3]
    str[a..b] = _p
  when 'reverse'
    str[a..b] = str[a..b].reverse
  when 'print'
    puts str[a..b]
  end
end

