n = gets.to_i
u = n.times.map{gets.chomp}
m = gets.to_i
open = false
m.times do
    t = gets.chomp
    if !u.include?(t)
        puts "Unknown #{t}"
    else
        if open
            puts "Closed by #{t}"
            open = !open
        else
            puts "Opened by #{t}"
            open = !open
        end
    end
end