{-# LANGUAGE BangPatterns #-} import qualified Data.Vector.Fusion.Stream.Monadic as VFSM main :: IO () main = do q <- readLn :: IO Int rep q $ \_ -> do [d, a, b] <- map (read :: String -> Int) . words <$> getLine if a == 0 then print $ func b d - func 0 d else print $ func b d - func (a - 1) d func :: Int -> Int -> Int func x d = let (q, r) = divMod x (d - 1) in d * (d - 1) `div` 2 * q + r * (r + 1) `div` 2 stream :: Monad m => Int -> Int -> VFSM.Stream m Int stream !l !r = VFSM.Stream step l where step x | x < r = return $ VFSM.Yield x (x + 1) | otherwise = return $ VFSM.Done {-# INLINE [0] step #-} {-# INLINE [1] stream #-} -- | rep 10 -> 0 1 2 3 4 5 6 7 8 9 rep :: Monad m => Int -> (Int -> m ()) -> m () rep n = flip VFSM.mapM_ (stream 0 n) {-# INLINE rep #-}