#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << (x) << endl
using namespace std;

const int N = 100005;

template <class T>
void read (T &x) {
	int sgn = 1;
	char ch;
	x = 0;
	for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar()) ;
	if (ch == '-') ch = getchar(), sgn = -1;;
	for (; '0' <= ch && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
	x *= sgn;
}

template <class T>
void write (T x) {
	if (x < 0) putchar('-'), write(-x);
	else if (x < 10) putchar(x + '0');
	else write(x / 10), putchar(x % 10 + '0');
}

struct permutation {
	int n;
	vector<int> p;

	permutation () {
		n = 0;
	}
	permutation (int n) {
		this -> n = n;
		for (int i = 0; i < n; i++) p.push_back(i);
	}

	permutation& operator = (permutation rhs) {
		n = rhs.n;
		p = rhs.p;
		return *this;
	}

	permutation operator * (permutation rhs) const {
		permutation res(n);
		for (int i = 0; i < n; i++) res.p[i] = p[rhs.p[i]];
		return res;
	}

	permutation inv () const {
		permutation res(n);
		for (int i = 0; i < n; i++) res.p[p[i]] = i;
		return res;
	}

	void output () {
		for (int i = 0; i < n; i++) write(p[i] + 1), putchar(' ');
		putchar('\n');
	}

} id, p, q;

int n, k;

permutation qpow (permutation p, int k) {
	permutation res(p.n);
	while (k) {
		if (k & 1) res = res * p;
		p = p * p, k >>= 1;
	}
	return res;
}

vector<int> seq[N];
int main () {
	read(n), read(k);
	id = p = q = permutation(n);
	for (int i = 0; i < n; i++) {
		read(p.p[i]), p.p[i]--;
	}
	for (int i = 0; i < n; i++) {
		read(q.p[i]), q.p[i]--;
	}

	if (k == 1) p.output();
	else {
		permutation a = qpow(q * p.inv() * q.inv() * p, (k - 2) / 6), b;
		if (k % 6 == 1) a = a * q * p.inv() * q.inv(), b = p;
		if (k % 6 == 2) b = q;
		if (k % 6 == 3) b = q * p.inv();
		if (k % 6 == 4) a = a * q, b = p.inv();
		if (k % 6 == 5) a = a * q * p.inv(), b = q.inv();
		if (k % 6 == 0) a = a * q * p.inv(), b = q.inv() * p;
		(a * b * a.inv()).output();
	}
	return 0;
}