import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.ByteString.Char8 (ByteString) import qualified Data.ByteString.Char8 as B import Data.List import Data.Char (isSpace) main :: IO () main = do solve <$> replicateM 1000 (getl $ readil B.readInt) >>= print solve :: [[Int]] -> Int solve = foldl' f 0 where f c e = if win e then c + 1 else c win [n, k] = (n - 1) `mod` (k + 1) /= 0 getl :: (ByteString -> a) -> IO a getl f = f <$> B.getLine readil :: Integral a => (ByteString -> Maybe (a, ByteString)) -> ByteString -> [a] readil f = unfoldr g where g s = do (n, s') <- f s return (n, B.dropWhile isSpace s')