#define DEBUG 1

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

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int p[100000],q[100000],P[100000],Q[100000];
int R[100000],r[100000];
int n[31][100000];
int ans[100000];
int apply(int *ans,int *perm,int N) {
    int i;
    for (i = 0; i < N; i++) ans[i] = perm[ans[i]];
    return 0;
}
int a[10][100000];
int main() {
    int i,j;
    int N,K;
    scanf("%d %d",&N,&K),K--;
    for (i = 0; i < N; i++) scanf("%d",&p[i]),p[i]--,P[p[i]] = i;
    for (i = 0; i < N; i++) scanf("%d",&q[i]),q[i]--,Q[q[i]] = i;
    if (K < 10) {
        for (i = 0; i < N; i++) a[0][i] = p[i],a[1][i] = q[i];
        for (i = 2; i <= K; i++) {
            for (j = 0; j < N; j++) a[i][a[i-2][j]] = a[i-1][j];
        }
        for (i = 0; i < N; i++) printf("%d ",a[K][i]+1);
        printf("\n");
        return 0;
    }

    for (i = 0; i < N; i++) ans[i] = i,R[i] = i,r[i] = i;
    apply(ans,Q,N);
    apply(R,p,N),apply(R,q,N),apply(R,P,N),apply(R,Q,N);
    int c = (K-3)/6;
    for (i = 0; i < N; i++) n[0][i] = R[i];
    for (i = 1; i <= 30; i++) {
        for (j = 0; j < N; j++) n[i][j] = n[i-1][n[i-1][j]];
    }
    for (i = 0; i < N; i++) {
        for (j = 30; j >= 0; j--) {
            if (c & (1 << j)) ans[i] = n[j][ans[i]];
        }
    }
    c = K % 6;
    if (c == 0) apply(ans,p,N);
    else if (c == 1) apply(ans,p,N),apply(ans,q,N),apply(ans,P,N);
    else if (c == 2) apply(ans,p,N),apply(ans,q,N),apply(ans,P,N),apply(ans,P,N);
    else if (c == 3) apply(ans,P,N);
    else if (c == 4) apply(ans,p,N),apply(ans,Q,N),apply(ans,P,N);
    else if (c == 5) apply(ans,p,N),apply(ans,p,N),apply(ans,Q,N),apply(ans,P,N);
    c = K/6;
    apply(r,q,N),apply(r,p,N),apply(r,Q,N),apply(r,P,N);
    for (i = 0; i < N; i++) n[0][i] = r[i];
    for (i = 1; i <= 30; i++) {
        for (j = 0; j < N; j++) n[i][j] = n[i-1][n[i-1][j]];
    }
    for (i = 0; i < N; i++) {
        for (j = 30; j >= 0; j--) {
            if (c & (1 << j)) ans[i] = n[j][ans[i]];
        }
    }
    apply(ans,q,N);
    for (i = 0; i < N; i++) printf("%d ",ans[i]+1);
    printf("\n");
    
    return 0;
}



Measured memory_bytes: 18668