str = gets.chomp
n = gets.to_i
 
for i in 1..n
  order = gets.chomp.split
  a = order[1].to_i
  b = order[2].to_i
 
 if order[0] == "print"
  puts str[a..b]
 elsif order[0] == "reverse"
  str[a..b] = str[a..b].reverse
 elsif order[0] == "replace"
  str[a..b] = order[3]
  end
end
