x = gets
y = x.split(",")
a = y[0].to_i
b = y[1].to_i

scorebord = Hash.new
score = []
until a == 0 && b == 0
 scorebord[a.to_s] = b 
 score << b
 x = gets
 y = x.split(",")
 a = y[0].to_i
 b = y[1].to_i
end

score1 = score.sort.reverse
score2 = score1.uniq

nn = gets
until nn.nil?
 n = nn.chomp
 point = scorebord[n]
 indexnum = score2.index(point)
 puts indexnum + 1
 nn = gets
end
