menber = []
while (arg = gets.split(",").map(&:to_i)) != [0, 0]
  menber << arg
end
menber.sort_by!{|item|-item[1]}
rank = Array.new(menber.length)
temp = [0, 31]
menber.each{|item|
  if item[1] != temp[1]
    temp[1] = item[1]
    temp[0] += 1
  end
  rank[item[0] - 1] = temp[0]
}
while n = gets
  puts rank[n.to_i - 1]
end