hash = Array.new
ps = Array.new
loop{
  n,p = gets.split(",").map(&:to_i)
  break if(n|p)==0
  hash[n]=p
  ps<<p unless ps.include?(p)
}
ps.sort!{|a,b| b<=>a}
while n = gets do
  puts ps.index(hash[n.to_i])+1 if hash[n.to_i]
end