
score = []
until (t = gets.split(',').map(&:to_i))== [0,0]
    score << [t[0] , t[1], 0]
end

score.sort!{ |x, y| x[1] <=> y[1] }.reverse!
score.length.times do |i|
#    p score
    if i == 0
        score[i][2] = 1
    else
        if score[i-1][1] == score[i][1]
            score[i][2] = score[i-1][2]
        else
            score[i][2] = score[i-1][2] + 1
        end
    end
end

while gets
    puts score[$_.to_i][2]
end