#include <bits/stdc++.h>

template <class T>
inline void read(T &x) {
	static char ch; 
	while (!isdigit(ch = getchar())); 
	x = ch - '0'; 
	while (isdigit(ch = getchar()))
		x = x * 10 + ch - '0'; 
}

const int MaxN = 1e5 + 5; 

int n, K; 
struct per {
	int a[MaxN];

	inline void scan() {
		for (int i = 1; i <= n; ++i) {
			read(a[i]); 
		}
	}
	inline void print() {
		for (int i = 1; i <= n; ++i) {
			printf("%d%c", a[i], " \n"[i == n]); 
		}
	}

	inline per inv() {
		per res; 
		for (int i = 1; i <= n; ++i) {
			res.a[a[i]] = i; 
		}
		return res; 
	}
	inline per operator * (const per &rhs) const {
		per res; 
		for (int i = 1; i <= n; ++i) {
			res.a[i] = a[rhs.a[i]]; 
		}
		return res; 
	}
	inline per operator ^ (int p) const {
		per res; 

		static bool vis[MaxN]; 
		for (int i = 1; i <= n; ++i) vis[i] = false; 
		for (int i = 1; i <= n; ++i)
			if (!vis[i]) {
				int x = i, len = 0; 
				std::vector<int> cur; 

				while (!vis[x]) {
					cur.push_back(x); 
					vis[x] = true, x = a[x], ++len; 
				}

				for (int j = 0; j < len; ++j) {
					res.a[cur[j]] = cur[(j + p) % len]; 
				}
			}
		return res; 
	}
}a[10], A, B; 

int main() {
#ifdef orzczk
	freopen("permutation.in", "r", stdin); 
#endif
	
	read(n), read(K); 

	a[1].scan(), a[2].scan(); 
	for (int i = 3; i <= 6; ++i) {
		a[i] = a[i - 1] * a[i - 2].inv(); 
	}
	
	A = a[2] * a[1].inv() * a[2].inv() * a[1]; 
	B = A.inv(); 

	int t = (K - 1) / 6; 
	((A ^ t) * a[K - 6 * t] * (B ^ t)).print(); 

	return 0; 
}