s = gets.chomp
l = s.length
q = gets.to_i
for i in 1..q
  t = gets.split
  a = t[1].to_i
  b = t[2].to_i
  case t[0]
  when "replace"
    p = t[3]
    s = s[0,a] + p + s[b+1,l-b-1]
  when "reverse"
    u = s[a, b-a+1].reverse
    s = s[0,a] + u + s[b+1,l-b-1]
  when "print"
    puts s[a,b-a+1]
  end
end