let rec read () =
  let n, p = Scanf.scanf "%d,%d\n" (fun x y -> (x, y)) in
  if n = 0 && p = 0 then []
  else (n, p) :: read ()

let rec setRank r = function
  | [] -> []
  | (n, p) :: [] -> [(n, p, r)]
  | (n1, p1) :: (n2, p2) :: rest -> if p1 = p2 then (n1, p1, r) :: setRank r ((n2, p2) :: rest)
                                    else (n1, p1, r) :: setRank (r+1) ((n2, p2) :: rest)

let find tbl n = let (_,_,r) = List.find (fun (m, p, r) -> n = m) tbl in r

let _ =
  let tbl =setRank 1 (List.sort (fun (n1,p1) (n2,p2) -> compare p2 p1) (read ())) in
  try
    while true do
      let r = Scanf.scanf "%d\n" (fun x -> find tbl x) in
      Printf.printf "%d\n" r
    done
  with
    End_of_file -> ()