str = gets.chomp
q = gets.to_i

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

	case command[0]
	when 'print'
		puts str[a, b-a+1]
	when 'reverse'
		str = str[0, a] + str[a, b-a+1].reverse + str[b+1, str.length-b]
	when 'replace'
		str = str[0, a] + command[3] + str[b+1, str.length-b]
	end
end