import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.List.Split (splitOn) main :: IO () main = do n <- getl read solve <$> replicateM n (getl words) >>= print solve :: [[String]] -> Int solve = sum . map f where toMinutes = (\[h, m] -> h * 60 + m) . map read . splitOn ":" f [s1, s2] = (toMinutes s2 - toMinutes s1) `mod` 1440 getl :: (String -> a) -> IO a getl f = f <$> getLine