import Control.Applicative import Control.Monad import Data.List import Text.Printf type Vector a = [a] type Matrix a = [Vector a] (!+!) :: Num a => Vector a -> Vector a -> Vector a (!+!) a b = zipWith (+) a b vneg :: Num a => Vector a -> Vector a vneg a = map negate a (!-!) a b = a !+! (vneg b) (!.!) :: Num a => Vector a -> Vector a -> a (!.!) a b = sum $ zipWith (*) a b (!*) :: Num a => Vector a -> a -> Vector a (!*) a n = map (*n) a (*!) b a = a !* b (!/) a b = a !* (1 / b) vabs :: (Real a, Num a) => Vector a -> Double vabs a = sqrt $ sum $ map (realToFrac . (^2)) a (|*|) :: Num a => Matrix a -> Matrix a -> Matrix a (|*|) a b = map (\va -> map (\vb -> sum $ zipWith (*) va vb) (transpose b)) a (|+|) :: Num a => Matrix a -> Matrix a -> Matrix a (|+|) a b = zipWith (zipWith (+)) a b main = do [n,px,py] <- map read . words <$> getLine :: IO [Int] ms <- reverse <$> do replicateM n $ do com <- map read . words <$> getLine :: IO [Int] return $ case com of [1,dx] -> [[1,0,dx],[0,1,0],[0,0,1]] [2,dy] -> [[1,0,0],[0,1,dy],[0,0,1]] [3] -> [[0,1,0],[-1,0,0],[0,0,1]] mapM_ (\[[x],[y],_] -> printf "%d %d\n" x y) $ reverse . map (|*| [[px],[py],[1]]) $ (scanl1 (|*|) ms)