import Control.Monad import Data.Char main :: IO () main = do t <- readLn replicateM_ t $ do xs <- getLine print $ head $ last $ takeWhile (not . null) $ iterate step (map digitToInt xs) step :: [Int] -> [Int] step xs = zipWith add xs (tail xs) where add a b | s >= 10 = s`div`10+s`mod`10 | otherwise = s where s = a+b