{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List (foldl')
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST
import qualified Data.Sequence as S

import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
readInt = fst . fromJust . B.readInt
readInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine :: IO [Int]
readIntegers = map (fst . fromJust . B.readInteger) . B.words <$> B.getLine :: IO [Integer]
read2dInts = map (map (fst . fromJust . B.readInt) . B.words) . B.lines <$> B.getContents
readVInts = map (fst . fromJust . B.readInt) . B.lines <$> B.getContents

main :: IO ()
main = do
  q <- readLn :: IO Int
  qs <- read2dInts
  -- qs <- replicateM q $ map read . words <$> getLine :: IO [[Int]]
  solve qs

type ZippedList a = ([a], [a])

empty :: ZippedList a
empty = ([], [])

singleton :: a -> ZippedList a
singleton x = ([], [x])

insert :: a -> ZippedList a -> ZippedList a
insert x (as, bs) = (as, x:bs)

move :: Int -> ZippedList a -> ZippedList a
move !d org@(as, bs)
  | d > 0  = move (d - 1) (b:as, tail bs)
  | d < 0  = move (d + 1) (tail as, a:bs)
  | d == 0 = org
  where
    a = head as
    b = head bs

delete :: ZippedList a -> ZippedList a
delete (as, b:bs) = (as, bs)

output :: (Show a) => ZippedList a -> IO ()
output (left, right) = do
  putStr . unlines . map show . reverse $ left
  putStr . unlines . map show $ right

solve :: [[Int]] -> IO()
solve = output . foldl' f empty
  where
    f :: ZippedList Int -> [Int] -> ZippedList Int
    f s (query:qs) 
      | query == 0 = insert (head qs) s
      | query == 1 = move (head qs) s
      | query == 2 = delete s



