point = []
while line = gets
p,s = line.split(",").map(&:to_i)
break if p == 0 && s ==0
point[p] = s
end

rpoint = point.uniq.compact.sort.reverse
phash = {}
(0...rpoint.size).each do |i|
  phash[rpoint[i]] = i+1
end
while line = gets
n = line.chomp.to_i
puts phash[point[n]]
end
