#!/usr/bin/env ruby

status = false    # false: closed,  true: open
ids = {}          # key が id

nr = $stdin.readline.to_i
nr.times do
  id = $stdin.readline.chomp
  ids[id] = true
end

nr = $stdin.readline.to_i
nr.times do
  id = $stdin.readline.chomp

  if ids[id]

    status = !status
    if status
      puts "Opened by #{id}"
    else
      puts "Closed by #{id}"
    end

  else
    puts "Unknown #{id}"
  end

end

