import Control.Monad
import Data.List
import GHC.Exts

main = do
  [n,l,t] <- map read . words <$> getLine
  xws <- map (map read . words) <$> replicateM n getLine :: IO [[Int]]
  mapM_ print $ solve n l t xws

solve n l t xws = drop d ps ++ take d ps
  where
  d = sum (map (`div`l) ps') `mod` n
  moved x w = x + t * (3-w*2)
  ps = sort $ map (`mod`l) ps'
  ps' = [ moved x w | [x,w] <- xws ]
