//by yjz
#include<bits/stdc++.h>
using namespace std;
#define FF first
#define SS second
#define PB push_back
#define MP make_pair
#define foreach(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#ifndef LOCAL
#define cerr if(0)cout
#endif
typedef long long ll;
const int mod = 1e9+7;
//My i/o stream
struct fastio
{
	char s[100000];
	int it, len;
	fastio() {it=len=0;}
	inline char get()
	{
		if (it<len) return s[it++]; it=0;
		len=fread(s, 1, 100000, stdin);
		if (len==0) return EOF; else return s[it++];
	}
	bool notend()
	{
		char c=get();
		while (c==' '||c=='\n') c=get();
		if (it>0) it--;
		return c!=EOF;
	}
}_buff;
#define geti(x) x=getnum()
#define getii(x,y) geti(x),geti(y)
#define getiii(x,y,z) getii(x,y),geti(z)
#define puti(x) putnum(x),putchar(' ')
#define putii(x,y) puti(x),puti(y)
#define putiii(x,y,z) putii(x,y),puti(z)
#define putsi(x) putnum(x),putchar('\n')
#define putsii(x,y) puti(x),putsi(y)
#define putsiii(x,y,z) putii(x,y),putsi(z)
inline ll getnum()
{
	ll r=0; bool ng=0; char c; c=_buff.get();
	while (c!='-'&&(c<'0'||c>'9')) c=_buff.get();
	if (c=='-') ng=1, c=_buff.get();
	while (c>='0'&&c<='9') r=r*10+c-'0', c=_buff.get();
	return ng?-r:r;
}
template <class T> inline void putnum(T x)
{
	if (x<0) putchar('-'), x=-x;
	register short a[20]={}, sz=0;
	while (x) a[sz++]=x%10, x/=10;
	if(sz==0) putchar('0');
	for (int i=sz-1; i>=0; i--) putchar('0'+a[i]);
}
inline char getreal() {char c=_buff.get(); while (c<=32) c=_buff.get(); return c;}
ll qpow(ll x, ll k) {return k==0? 1: 1ll*qpow(1ll*x*x%mod,k>>1)*(k&1?x:1)%mod;}
const int maxn = 200111;
vector<int> tablen = {-1, 1, 2, 3, 5, 6};
int n, K, a[2][maxn], ia[2][maxn], c[maxn], ic[maxn], d[maxn], c0[4][maxn], cp[maxn], ans[maxn];
void getinv(int a[], int b[])
{
	static int tmp[maxn];
	for (int i=1; i<=n; i++) tmp[a[i]] = i;
	for (int i=1; i<=n; i++) b[i] = tmp[i];
}
void apply(int a[], int b[], int c[])
{
	static int tmp[maxn];
	for (int i=1; i<=n; i++) tmp[i] = b[a[i]];
	for (int i=1; i<=n; i++) c[i] = tmp[i];
}
void apply(int a[], int b[])
{
	static int tmp[maxn];
	for (int i=1; i<=n; i++) tmp[i] = b[a[i]];
	for (int i=1; i<=n; i++) a[i] = tmp[i];
}
void applyk(int a[], int b[], int K, int c[])
{
	static int tab[33][maxn], tmp[maxn];
	for (int i=1; i<=n; i++) tab[0][i] = b[i];
	for (int i=1; i<=30; i++) apply(tab[i-1], tab[i-1], tab[i]);
	for (int i=1; i<=n; i++) tmp[i] = a[i];
	for (int i=0; i<=30; i++)
	{
		if ((K>>i)&1)
		{
			apply(tmp, tab[i], tmp);
		}
	}
	for (int i=1; i<=n; i++) c[i] = tmp[i];
}
int main()
{
	getii(n, K); K--;
	for (int i=1; i<=n; i++) geti(a[0][i]);
	for (int i=1; i<=n; i++) geti(a[1][i]);
	getinv(a[0], ia[0]);
	getinv(a[1], ia[1]);
	for (int i=1; i<=n; i++)
	{
		cp[i] = c[i] = d[i] = ans[i] = i;
		c0[0][i] = ia[1][i];
		c0[1][i] = a[0][i];
		c0[2][i] = a[1][i];
		c0[3][i] = ia[0][i];
	}
	apply(cp, c0[0]);
	apply(cp, c0[1]);
	apply(cp, c0[2]);
	apply(cp, c0[3]);
	
	
	if (K<2)
	{
		for (int i=1; i<=n; i++) puti(a[K][i]);
	}
	else
	{
		int t = K%6;
		int sz = (K/6)*8+tablen[t];
		int l = (sz-1)/2;
		applyk(c, cp, l/4, c);
		for (int i=0; i<l%4; i++) apply(c, c0[i]);
		if (t==0) apply(d, a[0]);
		else if (t==1) apply(d, a[1]);
		else if (t==2) apply(d, ia[0]), apply(d, a[1]);
		else if (t==3) apply(d, ia[0]);
		else if (t==4) apply(d, ia[1]);
		else if (t==5) apply(d, a[0]), apply(d, ia[1]);
//		for (int i=1; i<=n; i++) cout<<c[i]<<" "; cout<<endl;
//		for (int i=1; i<=n; i++) cout<<d[i]<<" "; cout<<endl;
		
		apply(ans, c);
		apply(ans, d);
		getinv(c, ic);
		apply(ans, ic);
		for (int i=1; i<=n; i++) puti(ans[i]);
	}
	return 0;
}


Measured memory_bytes: 38912