score = {}
result = {}
while line = gets.chomp
  break if line == "0,0"
  p, s = line.split(",").map(&:to_i)
  result[p] = s
  score[s] = true
end

rank = score.keys.sort{|a, b| b<=>a}

while p = gets
  puts rank.index(result[p.to_i]) + 1
end