n = gets.to_i
u = []
n.times do
    u.push(gets.chomp)
end

lock = true

m = gets.to_i
m.times do
    s = gets.chomp
    if u.count(s) == 0
        puts "Unknown #{s}"
    elsif lock
        puts "Opened by #{s}"
        lock = false
    else
        puts "Closed by #{s}"
        lock = true
    end
end
