rank = {}

while str = STDIN.gets

  (a, b) = str.chomp.split(/,/).map(&:to_i)

  break if a == 0 && b == 0

  rank[a] = b

end

ranks = rank.values.uniq.sort{|a, b| b <=> a}.map.with_index(1){|v, i| [v, i]}.to_h

while str = STDIN.gets

  break if str == "\n"

  n = str.chomp.to_i
  puts ranks[rank[n]]

end