users = []
opened = false

user_line_count = gets.strip.to_i
user_line_count.times { users << gets.strip }

data_line_count = gets.strip.to_i
data_line_count.times do
  user = gets.strip
  if users.include?(user)
    opened = !opened
    puts "#{opened ? 'Opened' : 'Closed'} by #{user}"
  else
    puts "Unknown #{user}"
  end
end

