#20131114

key=[]
gets.to_i.times{
	key.push gets.chomp
}
lock = true
gets.to_i.times{
	id = gets.chomp
	if key.count(id) > 0
		if lock
			puts "Opened by #{id}" 
			lock = false
		else
			puts "Closed by #{id}"
			lock = true
		end
	else
		puts "Unknown #{id}"
	end
}