// Dmitry _kun_ Sayutin (2019)

#include <bits/stdc++.h>

using std::cin;
using std::cout;
using std::cerr;

using std::vector;
using std::map;
using std::array;
using std::set;
using std::string;

using std::pair;
using std::make_pair;

using std::tuple;
using std::make_tuple;
using std::get;

using std::min;
using std::abs;
using std::max;
using std::swap;

using std::unique;
using std::sort;
using std::generate;
using std::reverse;
using std::min_element;
using std::max_element;

#ifdef LOCAL
#define LASSERT(X) assert(X)
#else
#define LASSERT(X) {}
#endif

template <typename T>
T input() {
    T res;
    cin >> res;
    LASSERT(cin);
    return res;
}

template <typename IT>
void input_seq(IT b, IT e) {
    std::generate(b, e, input<typename std::remove_reference<decltype(*b)>::type>);
}

#define SZ(vec)         int((vec).size())
#define ALL(data)       data.begin(),data.end()
#define RALL(data)      data.rbegin(),data.rend()
#define TYPEMAX(type)   std::numeric_limits<type>::max()
#define TYPEMIN(type)   std::numeric_limits<type>::min()

vector<int> perm_mult(const vector<int>& a, const vector<int>& b) {
    vector<int> res(SZ(a), -1);

    for (int i = 0; i != SZ(a); ++i)
        res[i] = a[b[i]];

    return res;
}

vector<int> perm_inv(const vector<int>& a) {
    vector<int> res(SZ(a), -1);

    for (int i = 0; i != SZ(a); ++i)
        res[a[i]] = i;

    return res;
}

vector<int> perm_pow(vector<int> a, int k) {
    vector<int> res(SZ(a));
    std::iota(ALL(res), 0);

    while (k) {
        if (k % 2) {
            vector<int> resc = perm_mult(res, a);
            res = resc;
        }

        vector<int> a_c = perm_mult(a, a);
        a = a_c;
        k /= 2;
    }

    return res;
}

#define mult perm_mult

int main() {
    std::iostream::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    // code here

#if 1
    int n = input<int>();
    int k = input<int>() - 1;
    
    vector<int> p(n), q(n);
    for (int& el: p)
        el = input<int>() - 1;

    for (int& el: q)
        el = input<int>() - 1;

    vector<int> p_inv = perm_inv(p);
    vector<int> q_inv = perm_inv(q);
    
    vector<int> res;

    // vector<int> aaa = mult(q, mult(p_inv, mult(q_inv, mult(p, q_inv))));
    // for (int elem: aaa)
    //     cout << 1 + elem << " ";
    // cout << "\n";
    
    if (k == 0) {
        res = p;
    } else if (k == 1) {
        res = q;
    } else {
        k -= 2;

        int LEN = 4 * (k / 6);
        k %= 6;

        int fuck[6] = {0, 1, 2, 2, 3, 4};
        LEN += fuck[k];

        vector<int> center;
        if (k == 0)
            center = mult(q, p_inv);
        else if (k == 1)
            center = p_inv;
        else if (k == 2)
            center = q_inv;
        else if (k == 3)
            center = mult(q_inv, p);
        else if (k == 4)
            center = p;
        else if (k == 5)
            center = q;

        res = perm_pow(mult(mult(q, p_inv), mult(q_inv, p)), LEN / 4);

        if (LEN % 4 >= 1)
            res = perm_mult(res, q);
        if (LEN % 4 >= 2)
            res = perm_mult(res, p_inv);
        if (LEN % 4 >= 3)
            res = perm_mult(res, q_inv);

        res = perm_mult(res, center);

        if (LEN % 4 >= 3)
            res = perm_mult(res, q);
        if (LEN % 4 >= 2)
            res = perm_mult(res, p);
        if (LEN % 4 >= 1)
            res = perm_mult(res, q_inv);

        vector<int> right = perm_pow(mult(mult(p_inv, q), mult(p, q_inv)), LEN / 4);
        res = perm_mult(res, right);
    }

    for (int elem: res)
        cout << 1 + elem << " ";
    cout << "\n";

#endif
    
#if 0
    vector<vector<pair<char, int>>> seq(100);

    seq[0] = {{'p', 1}};
    seq[1] = {{'q', 1}};
    
    for (int i = 2; i < 100; ++i) {
        auto a = seq[i - 2];
        auto b = seq[i - 1];

        for (auto& elem: a) {
            elem.second = -elem.second;
        }
        reverse(ALL(a));
        
        vector<pair<char, int>> res;

        for (auto elem: b)
            res.emplace_back(elem);

        for (auto p: a) {
            if (not res.empty() and res.back().first == p.first)
                res.back().second += p.second;
            else
                res.push_back(p);

            if (res.back().second == 0)
                res.pop_back();
        }

        seq[i] = res;
    }

    for (int i = 0; i != 20; ++i) {
        cout << i << " ";
        for (auto elem: seq[i]) {
            for (int iter = 0; iter != abs(elem.second); ++iter)
                cout << elem.first << (elem.second > 0 ? "+" : "-") << " ";
        }

        cout << "\n";
    }

#endif
    
    return 0;
}


Measured memory_bytes: 4568