import Control.Applicative import Control.Monad main :: IO () main = do n <- readLn map solve <$> replicateM n f >>= mapM_ putStrLn where -- f = readi B.readInt <$> B.getLine f = map read <$> words <$> getLine solve :: [Int] -> String solve [a, b] = unwords . map show $ let x = pow b in [truncate . fst $ x, flip mod 10 . truncate . (* 10) . fst $ x, snd x] where pow :: Int -> (Double, Int) pow 1 = norm (fromIntegral a, 0) pow n | even n = let x = pow (n `div` 2) in mul x x | otherwise = let x = pow (n `div` 2) in mul (mul x x) (pow 1) mul :: (Double, Int) -> (Double, Int) -> (Double, Int) mul (x1, y1) (x2, y2) = norm (x1 * x2, y1 + y2) norm :: (Double, Int) -> (Double, Int) norm (x, y) | x < 10.0 = (x, y) | otherwise = norm (x / 10.0, y+1)