import Data.List (sort,nub)
import Data.List.Split
import Data.Map (Map, (!))
import qualified Data.Map.Strict as Map
main = do
  s <- getContents
  let t = span (\x->x /= "0,0") . lines $ s
  let (d',q') = t
  let d = map (\x->(head x, last x)) . map (map read . splitOn ",") $ d'
  let vals = reverse . nub . sort . map (\(x,y)->y) $ d
  let dd = Map.fromList d
  let q = map read . tail $ q'
  let q2= map (solv vals 1 . (dd !)) q
  mapM_ (putStrLn . show) q2

solv::[Int] -> Int -> Int -> Int
solv [] a _ = a
solv (x:xs) a qv
  | x > qv = solv xs (a+1) qv 
  | otherwise = a