r = {}
b = []
c = {}
while 1
	a = gets.split(",").map &:to_i
	break if a[0] == 0
	r[a[0]] = a[1]
	b = b - [a[1]]
	b.push(a[1])
end
b.sort!.reverse!
b.size.times{ |i|
	c[b[i]] = i+1
}
while a = gets
	p c[r[a.to_i]]
end