str = gets.chomp
gets.to_i.times do
	line = gets.chomp.split
	if (start_pos = line[1].to_i) == 0 then
		head = ""
	else
		head = str[0..start_pos - 1]
	end
	if (end_pos = line[2].to_i) == str.length - 1 then
		foot = ""
	else
		foot = str[(end_pos + 1)..(str.length - 1)]
	end
	body = str[start_pos..end_pos]
	if line[0] == "print" then
		puts body
		elsif line[0] == "replace" then
		str = head + line[3] + foot
	else
		str = head + body.reverse + foot
	end
end