{-# LANGUAGE
  ScopedTypeVariables, BangPatterns, TupleSections, ExplicitForAll,
  LambdaCase, MultiWayIf, Unsafe, RecordWildCards, FlexibleContexts, CPP,
  NoMonomorphismRestriction, GADTs, ImplicitParams,
  RankNTypes, EmptyDataDecls, EmptyCase, ViewPatterns #-}


import Data.Bits
import Data.List
import Data.Maybe
import Data.Tuple
import Data.Ord
import Data.Int
import Data.Word
import Data.Char
import Data.Function
import Data.STRef
import Data.IORef
import Data.Monoid
import System.IO
import Control.Applicative
import Control.Monad
import Control.Monad.Primitive
import Control.Monad.State.Strict
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.DeepSeq
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Builder as BSB
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap (IntMap)
import qualified Data.IntMap.Strict as IMS
import qualified Data.IntMap.Lazy as IML
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic as VG
import qualified Data.Vector.Generic.Mutable as VGM
import GHC.Exts (build)

-- import Control.Monad.ST.Unsafe

main :: IO ()
main = do
  [n,k] <- map readInt . words <$> getLine
  [p,q] <- replicateM 2 $ VU.map (subtract 1)
    . VU.unfoldrN n (runStateT $ rIntS) <$> BS.getLine
  let ?n = n
  let (kd6, km6) = (k-1) `divMod` 6
      actor = sympow (conjinv q p `comp` p) kd6
      p1 = conj actor p
      q1 = conj actor q
      ans = fst $ (!! km6) $ iterate' (\(!x,!y) -> (y,f x y)) (p1,q1)
  BSB.hPutBuilder stdout
    $ VU.foldr (\ !j r !sp -> sp <> BSB.intDec j <> r (BSB.char7 ' '))
       (\ !sp -> BSB.char7 '\n') (VU.map (+1) ans) (BSB.byteString BS.empty)
   

-- Aut_Set({0,..,n-1})
-- To be used under the constraint (?n :: Int)
-- INVARIANT : VU.length x == ?n for x :: Perm
-- INVARIANT : VU.all (uncurry (==)) $ VU.indexed $ sort x for x :: Perm
type Perm = VU.Vector Int

idperm :: (?n :: Int) => Perm
{-# INLINE idperm #-}
idperm = VU.generate ?n id

inv :: (?n :: Int) => Perm -> Perm
{-# INLINE inv #-}
inv = g idperm

comp :: Perm -> Perm -> Perm
{-# INLINE comp #-}
comp = VU.map . (VU.!)

-- f p q = qp^{-1}
f :: (?n :: Int) => Perm -> Perm -> Perm
{-# INLINE f #-}
f = VU.update_ (VU.replicate ?n (-1))

-- g p q = pq^{-1}
g :: (?n :: Int) => Perm -> Perm -> Perm
{-# INLINE g #-}
g = flip f

-- conj p x = pxp^{-1}
conj :: (?n :: Int) => Perm -> Perm -> Perm
{-# INLINE conj #-}
conj p x = g (comp p x) p

-- conjinv p x = px^{-1}p^{-1}
conjinv :: (?n :: Int) => Perm -> Perm -> Perm
{-# INLINE conjinv #-}
conjinv p x = g p (comp p x)

sympow :: (?n :: Int) => Perm -> Int -> Perm
{-# INLINE sympow #-}
sympow p 0 = idperm
sympow p k_ = VU.create $ do
  vec <- VU.thaw idperm
  pcopy <- if k_ > 0 then VU.thaw p else VU.thaw $ inv p
  let k = abs k_
  tmp <- VUM.replicate ?n 0
  let loop !p !tmp !k = do
        when (testBit k 0) $ forM_ [0 .. ?n-1] $ \i ->
          VUM.write vec i =<< VUM.read p =<< VUM.read vec i
        let k1 = shiftR k 1
        when (k1 > 0) $ do
          forM_ [0 .. ?n-1] $ \i ->
            VUM.write tmp i =<< VUM.read p =<< VUM.read p i
          loop tmp p k1
  loop pcopy tmp k
  return vec


rInt :: StateT BSL.ByteString Maybe Int
rInt = StateT $ BSL.readInt . BSL.dropWhile (<'!')
rIntS :: StateT BS.ByteString Maybe Int
rIntS = StateT $ BS.readInt . BS.dropWhile (<'!')

#define D(f,r,d) f::Integral a=>a->d;f=fromIntegral;r::String->d;r=read
#define C(f,r,g,h,d) D(f,r,d);g,h::RealFrac a=>a->d;g=floor;h=ceiling
C(_toInteger_,readInteger,floorInteger,ceilInteger,Integer)
C(toInt,readInt,floorInt,ceilInt,Int)
C(toI8,readI8,floorI8,ceilI8,Int8)
C(toI16,readI16,floorI16,ceilI16,Int16)
C(toI32,readI32,floorI32,ceilI32,Int32)
C(toI64,readI64,floorI64,ceilI64,Int64)
C(toWord,readWord,floorWord,ceilWord,Word)
C(toW8,readW8,floorW8,ceilW8,Word8)
C(toW16,readW16,floorW16,ceilW16,Word16)
C(toW32,readW32,floorW32,ceilW32,Word32)
C(toW64,readW64,floorW64,ceilW64,Word64)
D(toDouble,readDouble,Double)
D(toFloat,readFloat,Float)
#undef D
#undef C

{-# INLINE wrA #-}
wrA = A.writeArray
{-# INLINE rdA #-}
rdA = A.readArray
{-# INLINE mdA #-}
mdA arr f i = do
  ai <- rdA arr i
  let fai = f ai 
  wrA arr i fai
  return (ai,fai)
{-# INLINE mdA' #-}
mdA' arr f i = do
  !ai <- rdA arr i
  let !fai = f ai
  wrA arr i fai
  return (ai,fai)
{-# INLINE swapA #-}
swapA arr i j = do
  ai <- rdA arr i
  wrA arr i =<< rdA arr j
  wrA arr j ai

#define N(f,g,a,m)\
  f :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> e -> m (a i e); f=A.newArray;\
  g :: forall e i s. (C(a,m)A.Ix i) => (i,i) -> m (a i e); g=A.newArray_
#define C(a,m)
N(newIOA,newIOA_,IOArray,IO)
N(newSTA,newSTA_,STArray s,ST s)
#undef C
#define C(a,m) MArray (a) e (m), 
N(newIOUA,newIOUA_,IOUArray,IO)
N(newSTUA,newSTUA_,STUArray s,ST s)
#undef C
#undef N

-- The following code is copy-paste from the Data.List
-- in the package base-4.12.0.0.
-- For the license text, see http://hackage.haskell.org/package/base-4.12.0.0.

-- | 'iterate\'' is the strict version of 'iterate'.
--
-- It ensures that the result of each application of force to weak head normal
-- form before proceeding.
{-# NOINLINE [1] iterate' #-}
iterate' :: (a -> a) -> a -> [a]
iterate' f x =
    let x' = f x
    in x' `seq` (x : iterate' f x')

{-# INLINE [0] iterate'FB #-} -- See Note [Inline FB functions]
iterate'FB :: (a -> b -> b) -> (a -> a) -> a -> b
iterate'FB c f x0 = go x0
  where go x =
            let x' = f x
            in x' `seq` (x `c` go x')

{-# RULES
"iterate'"    [~1] forall f x.   iterate' f x = build (\c _n -> iterate'FB c f x)
"iterate'FB"  [1]                iterate'FB (:) = iterate'
 #-}


Measured memory_bytes: 14332