s = gets.chomp
n = gets.to_i
(1..n).each do |_x|
  op, x, y, z = gets.split
  x = x.to_i
  y = y.to_i
  case op
  when 'replace'
    s0 = (x == 0) ? '' : s[0..x - 1]
    s1 = (y == s.length - 1) ? '' : s[y + 1..-1]
    s = s0 + z + s1
  when 'reverse'
    s0 = (x == 0) ? '' : s[0..x - 1]
    s1 = (y == s.length - 1) ? '' : s[y + 1..-1]
    m = s[x..y]
    s = s0 + m.reverse + s1
  when 'print'
    puts s[x..y]
  end
end