program a_sequence_of_permutations
  implicit none
  integer :: n, k, i, loop
  integer :: p(100000), q(100000), p0(100000), q0(100000)
  p = 0
  q = 0
  read(*,*) n, k
  read(*,*) p(1:n)
  read(*,*) q(1:n)
  if (n.eq.1) then
    write(*,'(i0)') 1
    stop
  end if
  if (k.eq.1) then
    write(*,'(i0)',advance='no') p(1)
    do i = 2, n
      write(*,'(x,i0)',advance='no') p(i)
    end do
    write(*,*)
    stop
  else if (k.eq.2) then
    write(*,'(i0)',advance='no') q(1)
    do i = 2, n
      write(*,'(x,i0)',advance='no') q(i)
    end do
    write(*,*)
    stop
  end if
  p0 = p
  q0 = q
  loop = -1
  do i = 3, k
    call swap(n,p(1:n),q(1:n))
    if ((sum(abs(p(1:n)-p0(1:n))).eq.0).and.(sum(abs(q(1:n)-q0(1:n))).eq.0)) then
      loop = i-2
      exit
    end if
  end do
  if (loop.gt.0) then
    k = mod(k,loop) + 1
    if (k.eq.1) then
      write(*,'(i0)',advance='no') p(1)
      do i = 2, n
        write(*,'(x,i0)',advance='no') p(i)
      end do
      write(*,*)
      stop
    else if (k.eq.2) then
      write(*,'(i0)',advance='no') q(1)
      do i = 2, n
        write(*,'(x,i0)',advance='no') q(i)
      end do
      write(*,*)
      stop
    end if
    do i = 3, k
      call swap(n,p(1:n),q(1:n))
    end do
  end if
  write(*,'(i0)',advance='no') q(1)
  do i = 2, n
    write(*,'(x,i0)',advance='no') q(i)
  end do
  write(*,*)
  stop
contains
  subroutine swap(n,p,q)
    implicit none
    integer, intent(inout) :: n, p(n), q(n)
    integer :: r(n), i
    do i = 1, n
      r(p(i)) = q(i)
    end do
    p = q
    q = r
    return
  end subroutine swap
end program a_sequence_of_permutations