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

main :: IO ()
main = readLn >>= flip replicateM (head <$> readLine) >>= printRes . solve
    where
        printRes = mapM_ print 

solve :: [Int] -> [Int]
solve as = map select as
    where
        (a0 : a1 : _) = sortOn Down as 
        select a 
            | a == a0 = a1 
            | otherwise = a0

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