s = gets.chomp
q = gets.to_i
q.times do
  c,a,b,p = gets.chomp.split
  a = a.to_i
  b = b.to_i
  case c
  when "print"
    puts s[a..b]
  when "reverse"
    s[a..b] = s[a..b].reverse
  when "replace"
    s[a..b] = p
  end
end
