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

using ll=long long;
using vll=vector<ll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vpii=vector<pii>;

vi fastexp(const vi& perm, int x) {
    if (x > 1) {
        int n = perm.size();
        vi halfexp = fastexp(perm, x/2);
        vi res(n);
        for (int i=0; i<n; ++i) {
            if (x&1)
                res[i] = perm[halfexp[halfexp[i]]];
            else
                res[i] = halfexp[halfexp[i]];
        }
        return res;
    }
    assert(x == 1);
    return perm;
}


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, k;
    cin >> n >> k;
    vvi ais(6, vi(n));
    for (int i=0; i<n; ++i) {
        cin >> ais[0][i];
        --ais[0][i];
    }
    for (int i=0; i<n; ++i) {
        cin >> ais[1][i];
        --ais[1][i];
    }
    for (int j=2; j<6; ++j) {
        for (int i=0; i<n; ++i) {
            ais[j][ais[j-2][i]] = ais[j-1][i];
        }
    }

    int lowi = k%6;
    if (lowi == 0)
        lowi = 6;
    int x = (k - lowi)/6;

    vi per(n);
    for (int i=0; i<n; ++i)
        per[i] = ais[3][ais[0][i]];

    vi res;
    if (x == 0)
        res = ais[lowi-1];
    else {
        vi perexp = fastexp(per, x);
        res = vi(n);
        for (int i=0; i<n; ++i) {
            res[perexp[i]] = perexp[ais[lowi-1][i]];
        }
    }
    for (int i=0; i<n; ++i)
        cout << res[i]+1 << " ";
    cout << "\n";
}
