t,r=[],[]
while gets
  q=$_.split(",").map(&:to_i)
  break if q==[0,0]
  t<<q
end
t.sort!{|i,j| j[1]<=>i[1]}.each{|i,j| r<<j}
while gets
  q=$_.chomp.to_i
  t.each do |i,j|
    if i==q
      p r.uniq.index(j)+1
      break
    end
  end
end