str = gets.rstrip
q = gets.to_i

q.times do
	cmd, a, b, _p = gets.split
	a = a.to_i
	b = b.to_i

	case cmd
	when 'print'
		puts str[a..b]
	when 'reverse'
		str[a..b] = str[a..b].reverse
	when 'replace'
		str[a..b] = _p
	end
end