import           Control.Applicative
import           Control.Monad

hoge :: String -> (Int, Maybe Int)
hoge ('0' : ' ' : xs) = (0, Just $ (read . head . words) xs)
hoge ('1' : ' ' : xs) = (1, Just $ (read . head . words) xs)
hoge ('2'       : _ ) = (2, Nothing)

a :: [Int] -> (Int, Maybe Int) -> IO [Int]
a xs (0, Just n) = return $ xs ++ [n]
a xs (1, Just n) = do
  print $ (head . drop n) xs
  return xs
a xs (2, _) = return $ init xs

main = do
  n  <- readLn
  ls <- replicateM n (hoge <$> getLine)
  foldl (\accio o -> accio >>= (`a` o)) (return []) ls

