n,k = gets.split.map(&:to_i)
p = [nil] + gets.split.map(&:to_i)
q = [nil] + gets.split.map(&:to_i)
def f(p, q)
  a = []
  1.upto(p.size-1) do |i|
    a[p[i]] = q[i]
  end
  a
end
a = []
h = {}
rh = {}
count = 0
(k-2).times do
  a = f(p, q)
  count += 1
  break if h[a]
  p = q
  q = a
  h[a] = count
  rh[count-1] = a
end
if count == (k-2)
  puts a[1..-1].join(' ')
else
  puts rh[(k % [(count-1), 1].max) - 3][1..-1].join(' ')
end
