input_data = gets.chomp
n = input_data.to_i

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

input_data = gets.chomp
m = input_data.to_i

openFlug = false
m.times do
    gg = gets.chomp
    if arr.include?(gg) && openFlug == false
        puts 'Opened by' + " "+ gg
        openFlug = true
    elsif arr.include?(gg) && openFlug != false
        puts 'Closed by' + " "+ gg
        openFlug = false
    else
        puts 'Unknown' + " "+ gg
    end
end

