module Main where

import Control.Monad (replicateM, forM_)
import Data.List (sortOn)

solve :: [Int] -> [Int]
solve as = let
    largest:secondLargest:n = sortOn negate as
    in
        fmap (\a -> if a == largest then secondLargest else largest) as


main :: IO ()
main = do
    n <- read <$> getLine 
    as <- replicateM n (read <$> getLine)
    let ans =  solve as
    forM_ ans  print