import Data.List
import Data.Maybe
import Data.Ord
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = readParams >>= mapM_ print . solve . tail

readParams :: IO [Int]
readParams = map b2int . B.words <$> B.getContents
  where b2int = fst . fromJust . B.readInt

solve :: [Int] -> [Int]
solve as = map f as
  where f a     = if a == x then y else x
        (x:y:_) = sortOn Down as
