#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int maxN = 2 * (int)1e5 + 100;
int n;
vector < int > poly_mult(vector < int > a, vector < int > b) {
    vector < int > c(n);
    for (int i = 0; i < n; i++) {
        c[i] = a[b[i]];
    }
    return c;
}
vector < int > inv(vector < int > a) {
    vector < int > c(n);
    for (int i = 0; i < n; i++) {
        c[a[i]] = i;
    }
    return c;
}
vector < int > pw(vector < int > a, int k) {
    vector < int > ans(n);
    if (k == 0) {
        for (int i = 0; i < n; i++) ans[i] = i;
        return ans;
    }
    if (k == 1) return a;
    if (k & 1) return poly_mult(a, pw(a, k - 1));
    auto t = pw(a, k / 2);
    return poly_mult(t, t);
}
int k;
void print(vector < int > p) {
    for (int v : p) cout << v + 1 << " ";
    exit(0);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    cin >> n >> k;
    vector < int > p(n), q(n);
    for (int i = 0; i < n; i++) {
        cin >> p[i];
        p[i]--;
    }
    for (int i = 0; i < n; i++) {
        cin >> q[i];
        q[i]--;
    }
    while (k % 6 != 1) {
        auto t1 = poly_mult(q, inv(p));
        auto t2 = q;
        q = t1;
        p = t2;
        k--;
    }
    if (k == 1) {
        print(p);
    }
    auto pp = p;
    auto qq = q;
    for (int i = 0; i < 2; i++) {
        auto t = poly_mult(qq, inv(pp));
        pp = qq;
        qq = t;
    }
    // a[4] = qq;
    auto T = poly_mult(qq, p);
    auto T1 = pw(T, k / 6);
    auto T2 = pw(inv(T), k / 6);
    print(poly_mult(T1, poly_mult(p, T2)));
    return 0;
}
