import scala.io.StdIn.readLine
import scala.io.Source.stdin
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  var s = ""
  var a = new ArrayBuffer[(Int,Int)]
  while( { s = readLine.trim;s } != "0,0" ) {
    val n = s.split(",").map(_.toInt)
    a += ((n(1),n(0)))
  }
  val g = a.toArray.groupBy(n=>n._1).mapValues(_.map(_._2)).toSeq.sortWith(_._1 > _._1)
  stdin.getLines.foreach { s=>
    println(g.indexWhere(n => n._2.exists( i => i==s.toInt ))+1)
  }
}