import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = getLine >> readLine >>= printRes . solve
    where
        printRes (m, xs) = print m >> mapM_ (putStrLn . unwords . map show) xs

solve :: [Int] -> (Int, [[Int]])
solve as
    | minimum as >= 0 = build0 $ sort as
    | maximum as <= 0 = build1 $ sortOn Down as 
    | otherwise = build2 $ sort as
    where
        build0 (x : xs) = inner x xs
            where
                inner acc [y] = (y - acc, [[y, acc]])
                inner acc (y : ys) = (res, [acc, y] : zs)
                    where
                        (res, zs) = inner (acc - y) ys
        build1 (x : xs) = edit $ foldl' (\(acc, bcc) n -> (acc - n, [acc, n] : bcc)) (x, []) xs
            where
                edit (res, bcc) = (res, reverse bcc)
        build2 (x : xs) = inner $ sortOn Down xs
            where
                inner (y : ys) = build3 (x, []) ys
                    where
                        build3 (acc, bcc) (z : zs)
                            | z >= 0 = build3 (acc - z, [acc, z] : bcc) zs
                            | otherwise = build4 (y - acc, [y, acc] : bcc) zs
                        build3 (acc, bcc) _ = (y - acc, reverse $ [y, acc] : bcc)
                        build4 (acc, bcc) (z : zs) = build4 (acc - z, [acc, z] : bcc) zs
                        build4 (acc, bcc) _ = (acc, reverse bcc)

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine