s = gets.chomp
n = gets.to_i
n.times do
  xs = gets.chomp.split
  p xs

  a = xs[1].to_i
  b = xs[2].to_i
  len = b - a + 1
  case xs[0]
  when "replace"
    x = s.slice(0, a)
    y = s.slice(a+len, s.length)
    s = x + xs[3] + y
  when "reverse"
    x = s.slice(0, a)
    y = s.slice(a, len).reverse
    z = s.slice(a+len, s.length)
    s = x + y + z
  when "print"
    puts s.slice(a, len)
  end
end