open = {}
gets.to_i.times do
  open[gets.chomp] = false
end

gets.to_i.times do
  id = gets.chomp
  case 
  when open[id].nil?
    puts "Unknown " + id
  when open[id] == false
    puts "Opened by " + id
    open[id] = true
  when open[id] == true
    puts "Closed by " + id
    open[id] = false
  end
end