#include <iostream>
#include <vector>
using namespace std;

int N, K;
int P[1 << 18];
int Q[1 << 18];
bool used[1 << 18];

vector<int> Connect(vector<vector<int>> V) {
	vector<int> R(V[0].size(), 0);
	for (int i = 0; i < V[0].size(); i++) {
		int cx = i;
		for (int j = 0; j < V.size(); j++) cx = V[j][cx];
		R[i] = cx;
	}
	return R;
}

vector<int> Multiply(vector<int> V, int S) {
	vector<int> R(V.size(), 0);
	for (int i = 0; i < V.size(); i++) used[i] = false;
	for (int i = 0; i < V.size(); i++) {
		if (used[i] == true) continue;
		vector<int> vec; int cx = i;
		while (used[cx] == false) {
			used[cx] = true;
			vec.push_back(cx);
			cx = V[cx];
		}
		for (int j = 0; j < vec.size(); j++) R[vec[j]] = vec[(j + S) % vec.size()];
	}
	return R;
}

vector<int> simulator(vector<int> P, vector<int> Q, int K) {
	if (K == 1) return P;
	if (K == 2) return Q;
	for (int i = 3; i <= K; i++) {
		vector<int> R(N, 0);
		for (int j = 0; j < N; j++) R[P[j]] = Q[j];
		P = Q; Q = R;
	}
	return Q;
}

int main() {
	// Step #1. 入力
	cin >> N >> K;
	for (int i = 0; i < N; i++) { cin >> P[i]; P[i]--; }
	for (int i = 0; i < N; i++) { cin >> Q[i]; Q[i]--; }

	// Step #2. Vector に落とし込む
	vector<int> realP(N, 0);
	vector<int> realQ(N, 0);
	vector<int> subP(N, 0);
	vector<int> subQ(N, 0);
	for (int i = 0; i < N; i++) realP[i] = P[i];
	for (int i = 0; i < N; i++) realQ[i] = Q[i];
	for (int i = 0; i < N; i++) subP[P[i]] = i;
	for (int i = 0; i < N; i++) subQ[Q[i]] = i;

	// Step #3. 場合分け
	int M = (K - 1) / 6;
	vector<int> Answer;
	if (K <= 6) {
		Answer = simulator(realP, realQ, K);
	}
	else if (K % 6 == 1) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M - 1);
		vector<int> V3 = Connect({ subQ, subP, realQ, realP });
		vector<int> V4 = Multiply(V3, M - 1);
		Answer = Connect({ subQ, V2, realP, realQ, realP, V4, subQ, subP, realQ });
	}
	else if (K % 6 == 2) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M - 1);
		vector<int> V3 = Connect({ realQ, realP, subQ, subP });
		vector<int> V4 = Multiply(V3, M);
		Answer = Connect({ subQ, V2, realP, realQ, subP, V4, realQ });
	}
	else if (K % 6 == 3) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M - 1);
		vector<int> V3 = Connect({ realQ, realP, subQ, subP });
		vector<int> V4 = Multiply(V3, M);
		Answer = Connect({ subQ, V2, realP, realQ, subP, subP, V4, realQ });
	}
	else if (K % 6 == 4) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M - 1);
		vector<int> V3 = Connect({ realQ, realP, subQ, subP });
		vector<int> V4 = Multiply(V3, M);
		Answer = Connect({ subQ, V2, realP, realQ, subP, subQ, subP, V4, realQ });
	}
	else if (K % 6 == 5) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M);
		vector<int> V3 = Connect({ subQ, subP, realQ, realP });
		vector<int> V4 = Multiply(V3, M);
		Answer = Connect({ subQ, V2, realP, V4, subQ, subP, realQ });
	}
	else if (K % 6 == 0) {
		vector<int> V1 = Connect({ realP, realQ, subP, subQ });
		vector<int> V2 = Multiply(V1, M);
		vector<int> V3 = Connect({ subQ, subP, realQ, realP });
		vector<int> V4 = Multiply(V3, M);
		Answer = Connect({ subQ, V2, realP, realP, V4, subQ, subP, realQ });
	}

	// Step #4. 出力
	for (int i = 0; i < Answer.size(); i++) {
		if (i >= 1) cout << " ";
		cout << Answer[i] + 1;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 14480