def replace(str, st, ed, repl)
	str[st..ed] = repl
	return str
end

def reverse(str, st, ed)
	t = str.split(//)
	while st > ed do
	  t[st], t[ed] = t[ed], t[st]
	  st += 1
	  ed -= 1
	end
	return t.join("")
end

def print(str, st, ed)
	puts str[st..ed]
end


base = gets.chomp
  
n = gets.to_i
  
n.times do
  t = gets.split(" ")
  if t[0]=="replace"
    base = replace(base, t[1].to_i, t[2].to_i, t[3])
  elsif t[0]=="reverse"
    base = reverse(base, t[1].to_i, t[2].to_i)
  else
    print(base, t[1].to_i, t[2].to_i)
  end
  
end