#include<bits/stdc++.h>

using namespace std;

int N, T, aux2[100009], aux[100009], a[100009], b[100009], invA[100009], invB[100009], period[100009], ans[100009], ap[100009], cyc[100009];
vector < int > v[109];

void compose (int a[], int b[])
{
    for (int i=1; i<=N; i++)
        aux[i] = a[i];
    for (int i=1; i<=N; i++)
        a[i] = aux[b[i]];
}

void raiseTo (int p[], int E, int ans[])
{
//    printf ("^ %d\n", E);
    for (int i=1; i<=N; i++)
        ap[i] = 0;
    for (int i=1; i<=N; i++)
        if (ap[i] == 0)
        {
            int sz = 1; cyc[sz] = i;
            while (ap[cyc[sz]] == 0)
                ap[cyc[sz]] = 1,
                cyc[sz + 1] = p[cyc[sz]], sz ++;
            sz --;
            for (int j=1; j<=sz; j++)
                ans[cyc[j]] = cyc[(j - 1 + E) % sz + 1];
        }
/*    printf ("smart:");
    for (int i=1; i<=N; i++)
        printf (" %d", ans[i]);
    printf ("\n");
    for (int i=1; i<=N; i++)
        ans[i] = i;
    while (E --) compose (ans, p);
    printf ("brute:");
    for (int i=1; i<=N; i++)
        printf (" %d", ans[i]);
    printf ("\n");*/
}

void getInverse (int source[], int dest[])
{
    for (int i=1; i<=N; i++)
        dest[source[i]] = i;
}

void apply (int x[], int type)
{
//    printf ("+ %d\n", type);
    if (type == 1) compose (x, a);
    else
    if (type == 2) compose (x, b);
    else
    if (type == -1) compose (x, invA);
    else compose (x, invB);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

v[1].push_back (1);
v[2].push_back (2);
for (int i=3; i<=28; i++)
{
    for (auto it : v[i - 1])
        v[i].push_back (it);
    for (auto it = v[i - 2].rbegin (); it != v[i - 2].rend (); it ++)
        if (!v[i].empty () && - *it + v[i].back () == 0) v[i].pop_back ();
        else v[i].push_back (- *it);
}
/*for (int i=1; i<=28; i++, printf ("\n"))
{
    int sz = 0;
    for (auto it : v[i])
    {
        printf ("%d ", it);
        sz = (sz + 1) & 3;
        if (sz == 0)
            printf (" |  ");
    }
}
exit (0);*/
scanf ("%d %d", &N, &T);
for (int i=1; i<=N; i++)
    scanf ("%d", &a[i]), period[i] = i;
for (int i=1; i<=N; i++)
    scanf ("%d", &b[i]), ans[i] = i;
getInverse (a, invA), getInverse (b, invB);
if (T <= 4)
{
    for (auto it : v[T])
        apply (ans, it);
}
else
{
    int times = (T + 1) / 6, r = (T - 5) % 6;

    apply (period, 2), apply (period, -1), apply (period, -2), apply (period, 1);
    raiseTo (period, times, ans);
/*    for (int i=1; i<=N; i++)
        printf ("%d%c", ans[i], " \n"[i == N]);*/

    if (r >= 3)
    {
        for (int pos = 8; pos < 12; pos ++)
            apply (ans, v[11 + r][pos]);
        r -= 3;
    }

    for (int i=1; i<=N; i++)
        period[i] = i;
    for (int pos = 8; pos < 12; pos ++)
        apply (period, v[11 + r][pos]);
//    apply (period, -2), apply (period, -1), apply (period, 2), apply (period, 1);
    raiseTo (period, times - 1, aux2);
    compose (ans, aux2);
/*    for (int i=1; i<=N; i++)
        printf ("%d%c", aux2[i], " \n"[i == N]);
    for (int i=1; i<=N; i++)
        printf ("%d%c", ans[i], " \n"[i == N]);*/

    for (int pos = 4; pos < v[5 + r].size (); pos ++)
        apply (ans, v[5 + r][pos]);
}
for (int i=1; i<=N; i++)
    printf ("%d%c", ans[i], " \n"[i == N]);
return 0;
}


Measured memory_bytes: 4736