import Control.Monad (forM_) import Control.Applicative ((<$>)) first :: (a, b, c) -> a first (x, _, _) = x second :: (a, b, c) -> b second (_, x, _) = x third :: (a, b, c) -> c third (_, _, x) = x log10 :: Floating a => a -> a log10 = logBase 10.0 solve :: Integral a => a -> a -> (a, a, a) solve a b = (x, y, z) where a' = fromIntegral a b' = fromIntegral b t1 = b' * log10 a' t2 = 10.0 ** (snd . properFraction $ t1) x = floor t2 y = floor (t2 * 10) `mod` 10 z = ceiling t1 - 1 main = do n <- readLn forM_ [1..n] $ \_ -> do [a, b] <- map read . words <$> getLine let ans = solve a b let x = first ans; y = second ans; z = third ans putStrLn $ show x ++ " " ++ show y ++ " " ++ show z