s=gets.chomp
gets.to_i.times{
  i,*p=gets.split

  case i
  when 'print'
    a,b=p.map(&:to_i)
    puts s[a..b]
  when 'reverse'
    a,b=p.map(&:to_i)
    s=s[0,a]+s[a..b].reverse+s[(b+1)..-1]
  when 'replace'
    a,b,c=p
    a=a.to_i
    b=b.to_i
    s=s[0,a]+c+s[(b+1)..-1]
  end
}
