#include <vector>
#include <stack>
#include <algorithm>
#include <iostream>
using namespace std;

vector<int> pmul(const vector<int> &p, const vector<int> &q) {
    int n = p.size()-1;
    vector<int> ans(n+1);
    for (int i = 1; i <= n; i++) ans[i] = p[q[i]];
    return ans;
}

vector<int> ppow(vector<int> &p, int k) {
    int n = p.size()-1;
    vector<int> ans(n+1), pw = p;
    for (int i = 1; i <= n; i++) ans[i] = i;
    while (k > 0) {
        if (k % 2 != 0) ans = pmul(ans, pw);
        pw = pmul(pw, pw);
        k >>= 1;
    }
    return ans;
}

int main() {
    int n, k; cin >> n >> k;
    vector<int> p(n+1), q(n+1), P(n+1), Q(n+1);
    for (int i = 1; i <= n; i++) {
        int x; cin >> x; p[i] = x; P[x] = i;
    }
    for (int i = 1; i <= n; i++) {
        int x; cin >> x; q[i] = x; Q[x] = i;
    }
    vector<int> ans;
    if (k == 1) ans = p;
    else if (k == 2) ans = q;
    else if (k == 3) ans = pmul(q, P);
    else if (k == 4) ans = pmul(q, pmul(P, Q));
    else {
        vector<int> r(n+1), R(n+1);
        for (int i = 1; i <= n; i++) {
            r[i] = q[P[Q[p[i]]]];
            R[i] = P[q[p[Q[i]]]];
        }
        int t = (k+1)/6;
        vector<int> s = ppow(r, t), S = ppow(R, t-1);
        vector<int> u = Q;
        int res = (k + 1) % 6;
        if (res > 0) u = pmul(p, u);
        if (res > 1) u = pmul(q, u);
        if (res > 2) {
            u = pmul(P, u);
            if (res == 4) u = pmul(P, u);
            if (res == 5) u = pmul(P, pmul(Q, u));
            u = pmul(q, u);
        }
        ans = pmul(s, pmul(u, S));
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << ' ';
    cout << endl;
}
