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

main :: IO ()
main = getLine >> readLine >>= printRes . solve 
    where
        printRes (n, xs)
            | n < 1 = print n 
            | otherwise = print n >> (putStrLn . unwords . map show) xs

solve :: [Int] -> (Int, [Int])
solve as = build 0 [] [n,(n - 1)..1] ras $ replicate m 0 ++ ras 
    where
        build c acc (x : xs) (y : ys) (z :  _ : zs)
            | y /= z = build (c + 1) (x : acc) xs ys zs 
            | otherwise = build c acc xs ys zs 
        build c acc _ _ _ = (c, acc)

        ras = reverse as 
        n = length as
        m 
            | odd n = 2 * (n `div` 2 + 1)
            | otherwise = n 

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