str = gets.chomp
q = gets.to_i
v = []

q.times do
  c = gets.split
  command = c[0]
  a = c[1].to_i
  b = c[2].to_i

  if command == 'print'
    v << str[a..b]
  elsif command == 'reverse'
    tmp = str[a..b].reverse
    str[a..b] = tmp
  else
    str[a..b] = c[3]
  end
end

v.each do |i|
  puts i
end

