str = gets.chomp
q = gets.to_i
q.times{
	x = gets.chomp.split
	order = x[0]
	a = x[1].to_i
	b = x[2].to_i
	p = x[3] if order == 'replace'

	puts str[a..b] if order == 'print'
	str = str[0...a] + str[a..b].reverse + str[b+1..-1] if order == 'reverse'
	str = str[0...a] + p + str[b+1..-1] if order == 'replace'
}
