-- AtCoder Beginner Contest 134 C
import Control.Monad
import Control.Applicative
import Data.List
import Data.Ord

toInt :: String -> Int
toInt x = read x :: Int

getInts = do
  x <- getLine
  let y = (map$toInt)$words x
  return y

merge :: Ord a => [a] -> [a] -> [a]
merge xs [] = xs
merge [] ys = ys
merge (x : xs) (y : ys)
  | x >= y = x : (merge xs (y : ys))
  | otherwise = y : (merge (x : xs) ys)

halve :: [a] -> ([a], [a])
halve xs = splitAt (div (length xs) 2) xs

msort :: Ord a => [a] -> [a]
msort [] = []
msort [x] = [x]
msort xs = merge (msort ys) (msort zs)
  where (ys, zs) = halve xs

top2 :: [a] -> [a]
top2 (x0 : (x1 : xs)) = [x0, x1]

sw :: Ord a => [a] -> a -> a
sw [x0, x1] x
  | x < x0 = x0
  | otherwise = x1

main :: IO()
main = do
  n <- readLn
  as <- replicateM n readLn
  let bs = top2 $ msort (as :: [Integer])
  mapM_ print $ map (sw bs) as