word = gets.chomp
order_num = gets.chomp.to_i
orders = []
order_num.times do
  orders << gets.chomp.split()
end

orders.each do |o|
  order = o[0]
  if order == "replace"
    word = word[0..o[1]] + o[3] + word[o[2+1..-1]]
  elsif order == "reverse"
    word = word[0..o[1]] + word[o[1]..o[2].reverse] + word[o[2] + 1]
  else
    puts word[o[1]..o[2]]
  end
end