n = gets.to_i
ids = {}
n.times{ ids[gets.chomp] = 1 }
m = gets.to_i
open = false
m.times{
    id = gets.chomp
    if ids[id]
        puts "#{open ? 'Closed' : 'Opened'} by #{id}"
        open = !open
    else
        puts "Unknown #{id}"
    end
}