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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "[";
    for (const auto &v : vec) {
        os << v << ",";
    }
    os << "]";
    return os;
}

template <typename T>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

// q(p(i))
vector<i64> composite(const vector<i64> &p, const vector<i64> &q){
    const i64 n=p.size();
    vector<i64> res(n);
    rep(i,0,n) res[i]=q[p[i]];
    return res;
}

vector<i64> inverse(const vector<i64> &p){
    const i64 n=p.size();
    vector<i64> res(n);
    rep(i,0,n) res[p[i]]=i;
    return res;
}

vector<i64> pow(vector<i64> p,i64 k){
    const i64 n=p.size();
    vector<i64> res(n);
    rep(i,0,n){
        res[i]=i;
    }
    while(k){
        if(k&1){
            res=composite(res,p);
        }
        p=composite(p,p);
        k>>=1;
    }
    return res;
}

vector<i64> f(const vector<i64> &p,const vector<i64> &q){
    const i64 n=p.size();
    vector<i64> res(n);
    rep(i,0,n) res[p[i]]=q[i];
    return res;
}

void solve() {
    //const i64 mod = 1'000'000'007;

    /*
    vector<string> vs(30);
    vs[1]="a";
    vs[2]="b";
    rep(i,3,vs.size()){
        vs[i]=vs[i-1];
        for(i64 j=vs[i-2].size()-1; j>=0; --j){
            char c=vs[i-2][j];
            if(c=='a'){
                if(vs[i].back()=='a') vs[i].pop_back();
                else vs[i]+='A';
            }
            if(c=='A'){
                if(vs[i].back()=='A') vs[i].pop_back();
                else vs[i]+='a';
            }
            if(c=='b'){
                if(vs[i].back()=='b') vs[i].pop_back();
                else vs[i]+='B';
            }
            if(c=='B'){
                if(vs[i].back()=='B') vs[i].pop_back();
                else vs[i]+='b';
            }
        }
    }
    rep(i,1,vs.size()){
        cout << i << ": " << vs[i] << endl;
    }
     */

    i64 N,K;
    cin >> N >> K;

    vector<i64> p(N),q(N);
    rep(i,0,N){
        cin >> p[i];
        --p[i];
    }
    rep(i,0,N){
        cin >> q[i];
        --q[i];
    }

    if(K<=20){
        vector<vector<i64>> a(max(K+1,i64(3)));
        a[1]=p;
        a[2]=q;
        rep(i,3,K+1){
            a[i]=f(a[i-2],a[i-1]);
        }
        rep(i,0,N){
            cout << a[K][i]+1;
            if(i==N-1) cout << endl;
            else cout << " ";
        }
        return;
    }

    vector<i64> pi=inverse(p),qi=inverse(q);

    auto x= composite(composite(composite(p, qi), pi), q);
    auto y= composite(composite(composite(qi, p), q), pi);

    i64 loop=(K-2)/6, rem=K-(2+loop*6);
    auto prev=composite(composite(inverse(pow(x,loop)),p),pow(x,loop));
    auto ans=composite(composite(pow(y,loop),q),pow(x,loop));
    rep(i,0,rem){
        auto tmp=ans;
        ans=f(prev,ans);
        prev=tmp;
    }

    rep(i,0,N){
        cout << ans[i]+1;
        if(i==N-1) cout << endl;
        else cout << " ";
    }
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 10984