#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<string>
#include<stack>
#include<algorithm>
#include<cmath>
#include<set>
#include<queue>
#include<sstream>
#include<utility>
#include<map>
#include<ctime>
#include<cstdio>
#include<cassert>
#include<functional>




using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;

#define show(x) cerr << x
#define debug(x) show(#x << ": " << (x) << endl)

const long double PI = 3.14159265358979323846;
const long double eps = 1e-5;
const int INF = numeric_limits<int>::max();
const ll LINF = numeric_limits<ll>::max();
const ll mod = 1000 * 1000 * 1000 + 7;


vector<int> inv(const vector<int>& a) {
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i < n; ++i)
        res[a[i]] = i;
    return res;
}


vector<int> mult(const vector<int>& a, const vector<int>& b) {
    int n = a.size();
    vector<int> res(n);
    for (int i = 0; i < n; ++i) {
        res[i] = a[b[i]];
    }
    return res;
}

vector<int> power(vector<int> a, int n) {
    int sz = a.size();
    vector<int> res(sz);
    for (int i = 0; i < sz; ++i)
        res[i] = i;
    while (n) {
        if (n & 1)
            res = mult(res, a);
        a = mult(a, a);
        n /= 2;
    }
    return res;
}



void solve() {
    int n, k;
    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];
    }
    int tr = 20;
    if (k < tr) {
        vector<vector<int> > res(k + 5);
        res[0] = p;
        res[1] = q;
        for (int i = 2; i < k; ++i)
            res[i] = mult(res[i - 1], inv(res[i - 2]));
        for (int i = 0; i < n; ++i) {
            cout << res[k - 1][i] + 1 << " ";
        }
        cout << endl;
        return;
    }
    int x = (k + 1) / 6;
    int r = (k + 1) % 6;
    vector<int> p1 = mult(mult(q, inv(p)), mult(inv(q), p));
    vector<int> p2 = mult(mult(inv(p), q), mult(p, inv(q)));
    p1 = power(p1, x);
    int y = x - 1;
    if (r >= 3)
        ++y;
    p2 = power(p2, y);
    vector<int> p3;
    if (r == 0) {
        p3 = inv(q);
    }
    if (r == 1) {
        p3 = mult(p, inv(q));
    }
    if (r == 2) {
        p3 = mult(q, mult(p, inv(q)));
    }
    if (r == 3) {
        p3 = q;
    }
    if (r == 4) {
        p3 = mult(q, inv(p));
    }
    if (r == 5) {
        p3 = mult(mult(q, inv(p)), inv(q));
    }
    vector<int> res = mult(p1, mult(p3, p2));
    for (int i = 0; i < res.size(); ++i)
        cout << res[i] + 1 << " ";
    cout << endl;

    
    




}

//#define LOCAL

int main() {
    ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    solve();


#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif	
    return 0;
}

Measured memory_bytes: 3912