data=[]
score=[]

while true
  p,s=gets.chomp.split(",").map { |s| s.to_i }
  break if p==0&&s==0
  data.push([p,s,0])
  score.push(s)
end

score=score.uniq.sort.reverse
score.size.times{|i|
  data.size.times{|j|
    if data[j][1]==score[i] then
      data[j][2]=i+1
    end
  }
}

while q=gets
  q=q.chomp.to_i
  data.size.times{|i|
    if data[i][0]==q then
      p data[i][2]
      break
    end
  }
end

