#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <tuple>
template <typename T> constexpr T my_abs(const T &x) { return x < 0 ? -x : x; }
using ll = long long;
struct permutation : std::vector<int>
{
	permutation(int n = 0) { resize(n); for (int i = 0; i < n; i++) at(i) = i; }
	inline permutation operator *(const permutation &a) const
	{
		permutation res(size());
		for (int i = 0; i < size(); i++)
			res[i] = at(a[i]);
		return res;
	}
	inline permutation inv() const
	{
		permutation res(size());
		for (int i = 0; i < size(); i++)
			res[at(i)] = i;
		return res;
	}
};
inline permutation quick_pow(permutation a, int n)
{
	permutation res(a.size());
	while (n)
	{
		if (n & 1)
			res = res * a;
		a = a * a;
		n >>= 1;
	}
	return res;
}
inline void output(permutation a)
{
	for (int i = 0; i < a.size(); i++)
		printf("%d%c", a[i] + 1, " \n"[i + 1 == a.size()]);
}
int main()
{
	// freopen("AGC031-D.in", "r", stdin);
	int n, k;
	scanf("%d%d", &n, &k);
	permutation a(n), b(n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
		a[i]--;
	}
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &b[i]);
		b[i]--;
	}
	if (k == 1)
	{
		output(a);
		return 0;
	}
	if (k == 2)
	{
		output(b);
		return 0;
	}
	permutation ra = a.inv(), rb = b.inv();
	if (k == 3)
	{
		output(b * ra);
		return 0;
	}
	k -= 4;
	permutation pl = quick_pow(rb * a * b * ra, k / 6);
	permutation pr = quick_pow(ra * b * a * rb, k / 6);
	k %= 6;
	std::vector<permutation> vec = {rb, a, b, ra};
	std::vector<int> len = {1, 3, 4, 5, 7, 8};
	for (int i = 0; i < 4; i++)
	{
		if (i * 2 < len[k])
			pl = pl * vec[i];
		if (i * 2 + 1 < len[k])
			pr = vec[i] * pr;
	}
	output(b * ra * pl * pr);
	return 0;
}
