{-# 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 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_main = sympow (conjinv q p `comp` p) kd6
      ans = (!! km6)
        [conj actor_main p,
         conj actor_main q,
         conj actor_main (f p q),
         conjinv (actor_main `comp` q) p,
         conjinv (comp actor_main q `g` p) q,
         conj (comp actor_main q `g` comp q p) (g p q)]
  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
sympow p 0 = idperm
sympow p k = VU.create $ do
  vec <- VU.thaw idperm
  let loop !p !k = do
        when (testBit k 0) $ forM_ [0 .. ?n-1] $ VUM.modify vec (p VU.!)
        let k1 = shiftR k 1
        when (k1 > 0) $ loop (comp p p) k1
  if k >= 0 then loop p k else loop (inv p) (-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



Measured memory_bytes: 18940