#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long ll;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct info {int a[MAXN]; };
int n; ll m;
info inv(info a) {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[a.a[i]] = i;
	return res;
}
info unit() {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[i] = i;
	return res;
}
info operator * (info a, info b) {
	info res;
	for (int i = 1; i <= n; i++)
		res.a[i] = b.a[a.a[i]];
	return res;
}
info p, q, r;
info power(info a, ll x) {
	if (x == 0) return unit();
	if (x < 0) return power(inv(a), -x);
	info tmp = power(a, x / 2);
	if (x % 2 == 0) return tmp * tmp;
	else return tmp * tmp * a;
}
int main() {
	read(n), read(m);
	for (int i = 1; i <= n; i++)
		read(p.a[i]);
	for (int i = 1; i <= n; i++)
		read(q.a[i]);
	while (m % 6 != 1) {
		info r = inv(p) * q;
		p = q, q = r, m--;
	}
	r = power(inv(q) * p * q * inv(p), m / 6) * power(p, m / 6 + 1);
	info res = r * p * inv(r);
	for (int i = 1; i <= n; i++)
		printf("%d ", res.a[i]);
	return 0;
}