count :: Eq a => a -> [a] -> Int
count x = length . filter (== x)

ofa :: [Int] -> [Int]
ofa xs = map (flip count xs) xs

impl :: Int -> [Int] -> [Int] -> (Int , [Int])
impl c xs ys
    | xs == ys = (c , xs)
    | otherwise = impl (succ c) (ofa xs) xs

solve :: [Int] -> IO ()
solve xs = print c >> (putStrLn $ unwords $ map show ys)
    where
        (c , ys) = impl (-1) xs []

main :: IO ()
main  = readLn >>= nyan
    where
        nyan :: Int -> IO ()
        nyan 0 = return ()
        nyan _ = getLine >>= solve . map read .words >> main