s = gets.chomp

gets.to_i.times do
  o, b, e, r = gets.split
  b, e = b.to_i, e.to_i + 1
  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