class IdScore 
	def initialize(id=0,score=0,rank=0)
		@id, @score, @rank = id, score, rank
	end

	attr_accessor :id,:score,:rank
end

data = Array.new
while gets
	id,score = $_.split(',').map(&:to_i)
	break if id == 0 && score == 0
	data << IdScore.new(id,score,0)
	data.sort!{|p,q| p.score<=>q.score}.reverse!
end
rank = 1
0.upto(data.size-1) do |i|
	data[i].rank = rank
	break if i == data.size-1
	rank += 1 if data[i].score > data[i+1].score
end
data.sort!{|p,q| p.id<=>q.id}
while gets
	id = $_.to_i
	puts data[id-1].rank
end