points = {}
loop do
  i,n = gets.split(",").map(&:to_i)
  break if i==0 && n==0
  points[i] = n
end

ranks = []
points.values.uniq.sort.reverse.each_with_index do |point,rank|
  points.select{|k,v| v==point}.keys.each do |i|
    ranks[i] = rank+1
  end
end

readlines.each do |l|
  puts ranks[l.to_i]
end