import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Prelude hiding (readLn)

main :: IO ()
main = readLine >>= main'
    where
        main' (n : xs) = replicateM n readLn >>= print . solve xs

solve :: [Int] -> [Int] -> Int
solve [a, b, c] = check [] [] []
    where
        check xs ys zs (l : ls) = minimum [check (l : xs) ys zs ls, check xs (l : ys) zs ls, check xs ys (l : zs) ls, check xs ys zs ls]
        check xs@(_ : _) ys@(_ : _) zs@(_ : _) _ = 10 * (xl + yl + zl - 3) + abs (xn - a) + abs (yn - b) + abs (zn - c)
            where
                [(xn, xl), (yn, yl), (zn, zl)] = map (foldl' ff (0, 0)) [xs, ys, zs]
                ff (acc, len) x = (acc + x, len + 1)
        check _ _ _ _ = 10 ^ 10


readLn :: IO Int 
readLn = head <$> readLine

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