#include <bits/stdc++.h>
using namespace std;

vector<int> operator * (const vector<int> &a, const vector<int> &b){
	vector<int> c(a.size());
	for(int i = 0; i < a.size(); i++) c[i] = b[a[i]];
	return c;
}
vector<int> inv(const vector<int> &a){
	vector<int> b(a.size());
	for(int i = 0; i < a.size(); i++) b[a[i]] = i;
	return b;
}

char neg(char x){
	if(x == 'A') x = 'a';
	else if(x == 'a') x = 'A';
	else if(x == 'B') x = 'b';
	else if(x == 'b') x = 'B';
	else assert(false);
	return x;	
}

string inverse(string s){
	reverse(s.begin(), s.end());
	for (char& x : s){
		x = neg(x);
	}
	return s;
}

string process(string s){
	string z;
	for(char x : s){
		if(!z.empty() && z.back() == neg(x)){
			z.pop_back();
		} else {
			z += x;
		}
	}
	return z;
}

void test(){
	string x = "A";
	string y = "B";
	for(int j = 3; j < 100; j++){
		string z = process(inverse(x) + y);
		cout << j << " " << z << endl;
		x = y; y = z;
	}
	exit(0);
}

vector<int> bf(vector<int> p, vector<int> q, int k){
	if(k == 1) return p;
	for(int b = 2; b < k; b++){
		p = inv(p) * q;
		swap(p, q);
	}
	return q;
}

vector<int> expo(vector<int> p, int n){
	if(n == 0) return p * inv(p);
	if(n & 1) return p * expo(p, n-1);
	return expo(p*p, n/2);
}

vector<int> solve(vector<int> p, vector<int> q, int k){
	if(k <= 10) return bf(p, q, k);
	int c = (k - 4) / 6;
	vector<int> lhs = inv(q) * p * q * inv(p);
	vector<int> rhs = inv(lhs);
	return expo(lhs, c) * solve(p, q, k - c * 6) * expo(rhs, c);
}


int main(){
	cin.sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector<int> p(n), q(n);
	for(int i = 0; i < n; i++) cin >> p[i];
	for(int i = 0; i < n; i++) cin >> q[i];
	for(int i = 0; i < n; i++) p[i]--, q[i]--;
	vector<int> ans;
	ans = solve(p, q, k);
	//assert(ans == bf(p, q, k));
	for(int r = 0; r < n; r++){
		cout << ans[r] + 1 << ' ';
	}
	cout << '\n';
}