#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

int n,k;
int p[125252];
int q[125252];

int I[125252];

int pinv[125252];
int qinv[125252];

int p1[125252], p2[125252];

int f[125252];
int ans[125252];

int tmp[125252];
void mult(int ans[125252], int a[125252], int b[125252]){
  REP(i,n)tmp[i] = a[b[i]];
  REP(i,n)ans[i] = tmp[i];
}

int main(){
  scanf("%d%d",&n,&k);
  REP(i,n)scanf("%d",p+i),p[i]--;
  REP(i,n)scanf("%d",q+i),q[i]--;

  if(k==1){
    REP(i,n)printf("%d%c",p[i]+1,i==n-1?'\n':' ');
    return 0;
  }else if(k==2){
    REP(i,n)printf("%d%c",q[i]+1,i==n-1?'\n':' ');
    return 0;
  }
  
  REP(i,n)I[i]=i;
  REP(i,n)pinv[p[i]]=i;
  REP(i,n)qinv[q[i]]=i;
  // P1: -2 1 2 -1
  REP(i,n)p1[i] = i;
  mult(p1, p1, pinv);
  mult(p1, p1, q);
  mult(p1, p1, p);
  mult(p1, p1, qinv);
  // P2: 1 -2 -1 2 (= P1 inv)
  REP(i,n)p2[i] = i;
  mult(p2, p2, q);
  mult(p2, p2, pinv);
  mult(p2, p2, qinv);
  mult(p2, p2, p);
  // REP(i,n)p2[p1[i]] = i;

  REP(i,n)f[i]=i;

  int p2cnt = (k-2)/6;
  while(p2cnt){
    if(p2cnt&1)mult(f,f,p2);
    mult(p2,p2,p2);
    p2cnt >>= 1;
  }
  if(k%6==3){
    mult(f,f,p); mult(f,f,qinv);
  }else if(k%6==4){
    mult(f,f,q); mult(f,f,p); mult(f,f,qinv);
  }else if(k%6==5){
    mult(f,f,q);
  }else if(k%6==0){
    mult(f,f,q); mult(f,f,pinv);
  }else if(k%6==1){
    mult(f,f,q); mult(f,f,pinv); mult(f,f,qinv);
  }else if(k%6==2){
    mult(f,f,qinv);
  }
  int p1cnt = (k+1)/6;
  while(p1cnt){
    if(p1cnt&1)mult(f,f,p1);
    mult(p1,p1,p1);
    p1cnt >>= 1;
  }
  // if(k%6==3){
  //   mult(f,f,qinv); mult(f,f,p);
  // }else if(k%6==4){
  //   mult(f,f,qinv); mult(f,f,p); mult(f,f,q);
  // }else if(k%6==5){
  //   mult(f,f,q);
  // }else if(k%6==0){
  //   mult(f,f,pinv); mult(f,f,q);
  // }else if(k%6==1){
  //   mult(f,f,qinv); mult(f,f,pinv); mult(f,f,q);
  // }else if(k%6==2){
  //   mult(f,f,qinv);
  // }


  REP(i,n)ans[f[i]] = i;
  REP(i,n)printf("%d%c",ans[i]+1,i==n-1 ? '\n' : ' ');
  // REP(i,n)printf("%d%c",f[i]+1,i==n-1 ? '\n' : ' ');

  return 0;

  // jikken
  vi a, b;
  a.push_back(-1);
  b.push_back(-2);
  while(k-- >= 3){
    vi c = b;
    while(a.size()){
      int x = -a.back();
      a.pop_back();
      if(c.size() && c.back() == -x){
        c.pop_back();
      }else{
        c.push_back(x);
      }
    }
    // printf("%2d: ", k+3);
    // REP(i,c.size())printf("%d ",c[i]);puts("");
    a = b; b = c;
  }

  REP(i,n)f[i] = i;
  reverse(ALL(b));
  REP(i,b.size()){
    int v = b[i];
    if(v==1)mult(f,f,p);
    if(v==2)mult(f,f,q);
    if(v==-1)mult(f,f,pinv);
    if(v==-2)mult(f,f,qinv);
  }
  REP(i,n)ans[f[i]] = i;
  REP(i,n)printf("%d%c",ans[i]+1,i==n-1 ? '\n' : ' ');
  REP(i,n)printf("%d%c",f[i]+1,i==n-1 ? '\n' : ' ');

  return 0;
}


Measured memory_bytes: 5120