import Control.Applicative ((<$>)) import Control.Monad (replicateM) import Data.List main :: IO () main = do n <- getl read solve <$> replicateM n (getl words) >>= putStrLn solve :: [[String]] -> String solve = intercalate " " . map show . foldl' f [0, 0] where f :: [Int] -> [String] -> [Int] f [tc, mc] [t, s] = let x = 12 * read t `div` 1000 y = min x (length s) in [tc + y, mc + (length s) - y] getl :: (String -> a) -> IO a getl f = f <$> getLine