str = gets.chomp
q = gets.chomp.to_i

q.times do |i|
   order = gets.chomp.split
   partial_str = str[(order[1].to_i)..(order[2].to_i)]
   if order[0] == "print"
      puts partial_str
   elsif order[0] == "reverse"
      reverse_partial_str = partial_str.reverse
      str = str.sub(/#{partial_str}/, reverse_partial_str)
   elsif order[0] == "replace"
      str[(order[1].to_i)..(order[2].to_i)] = order[3]
   end
end