str = gets.chomp
gets.to_i.times do
  com, a, b, w = gets.chomp.split
  a = a.to_i
  b = b.to_i
  case com
  when 'replace'
    str[a..b] = w
  when 'reverse'
    str[a..b] = str[a..b].reverse
  when 'print'
    puts str[a..b]
  end
end