import Data.List
import qualified Data.Set as S

main :: IO ()
main = interact $ unlines . map (show . bfs) . parse . map (map read . words) . lines
 where
  parse [[0,0]] = []
  parse ([t,o]:xs) = (t, map (\[a,b]->(a,b)) os, (x,y)) : parse xs'
   where (os,([x,y]:xs')) = splitAt o xs

bfs :: (Int, [(Int,Int)], (Int,Int)) -> Int
bfs (t,os,i) = S.size $ advance 0 (S.singleton i) (S.singleton i)
 where
  os' = S.fromList os
  advance t' b r
   | t' == t = r
   | S.null b' = r
   | otherwise = advance (t'+1) (S.difference b' r) (S.union r b')
   where
    b' = S.difference (S.foldl' (\acc x -> S.union acc (S.fromList (neighbors x))) b b) os'
    neighbors (x,y) = [(x+1,y),(x-1,y),(x,y+1),(x,y-1),(x+1,y+1),(x-1,y-1)]