teams={}
scores_uniq={}
while line = STDIN.gets
  if line == "0,0\n" then break end
  p, s = line.chomp.split(',').map { |item| item.to_i }
  teams[p] = s
  scores_uniq[s]=1
end

scores = scores_uniq.keys.sort.reverse

rank={}
scores.each_with_index { |e, i| rank[e] = i+1 }

while q = STDIN.gets
  q = q.chomp.to_i
  puts rank[teams[q]]
end