import           Data.List

solve :: String -> Int
solve s = let ss  = sort s
              rss = reverse ss
          in  abs $ read ss - read rss

main :: IO ()
main = getLine >> getContents >>= mapM_ (print . solve) . lines