s = gets.chop
gets.to_i.times{
  m, a, b, c = gets.split
  an = a.to_i
  bn = b.to_i
  case m
  when 'print'
    puts s[an..bn]
  when 'reverse'
    s = s[0...an] << s[an..bn].reverse << s[bn+1..-1]
  else
    s = s[0...an] << c << s[bn+1..-1]
  end
}