s = gets.chomp

gets.to_i.times do
  o, b, e, r = gets.split
  b, e = [b, e].map &:to_i
  case o
  when 'print' then puts s[b..e]  
  when 'reverse' then s[b..e] = s[b..e].reverse
  when 'replace' then s[b..e] = r
  end
end