require 'set'
s = Set.new
h = {}
loop do
    k, point = gets.split(",").map(&:to_i)
    break if k == 0
    h[k] = point
    s << point
end
rank = {}
s.sort.reverse.each.with_index {|x, i| rank[x] = i+1}

while l = gets
    n = l.to_i
    puts rank[h[n]]
end

