#include <bits/stdc++.h>
// {{{ Definitions
#define reg register
#define pr std::pair<int, int>
#define fi first
#define se second
#define FIN(s) freopen(s, "r", stdin)
#define FOUT(s) freopen(s, "w", stdout)
#define FERR(s) freopen(s, "w", stderr)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define dputs(s) fprintf(stderr, s"\n")
#define rep(i, l, r) for (int i = l; i <= r; ++i)
#define lep(i, l, r) for (int i = l; i < r; ++i)
#define irep(i, r, l) for (int i = r; i >= l; --i)
#define ilep(i, r, l) for (int i = r; i > l; --i)
#define Rep(i, n) rep(i, 1, n)
#define Lep(i, n) lep(i, 1, n)
#define IRep(i, n) irep(i, n, 1)
#define ILep(i, n) ilep(i, n, 1)
typedef long long ll;
typedef long double ld;
// }}}
// {{{ Modular
namespace modular {
    const int MOD = 1000000007;
    inline int add(int x, int y) { return (x += y) >= MOD ? x -= MOD : x; }
    inline void inc(int &x, int y) { (x += y) >= MOD ? x -= MOD : 0; }
    inline int mul(int x, int y) { return 1LL * x * y % MOD; }
    inline int qpow(int x, int y) {
        int ans = 1;
        for (; y; y >>= 1, x = mul(x, x))
            if (y & 1)
                ans = mul(ans, x);
        return ans;
    }
}; // namespace modular
// }}}
// {{{ Base

namespace Base {
    template <typename Tp> inline Tp input() {
        Tp x = 0, y = 1;
        char c = getchar();
        while ((c < '0' || '9' < c) && c != EOF) {
            if (c == '-')
                y = -1;
            c = getchar();
        }
        if (c == EOF)
            return 0;
        while ('0' <= c && c <= '9')
            x = x * 10 + c - '0', c = getchar();
        return x *= y;
    }
    template <typename Tp> inline void read(Tp &x) { x = input<Tp>(); }
    template <typename Tp> inline void chmax(Tp &x, Tp y) { x < y ? x = y : 0; }
    template <typename Tp> inline void chmin(Tp &x, Tp y) { x > y ? x = y : 0; }
}; // namespace Base

// }}}
using namespace Base;

#define MAX_N 200007

int N, K;
int p[MAX_N], q[MAX_N], tmp[MAX_N], inv[MAX_N], tmp2[MAX_N], tmp3[MAX_N], a[10][MAX_N], f[MAX_N], res[MAX_N];

void getinv(int *p, int *f) {
    Rep(i, N) f[p[i]] = i;
}

void mul(int *a, int *b, int *f) {
    Rep(i, N) f[i] = a[b[i]];
}

int st[MAX_N], ans[MAX_N], pos[MAX_N], top;
bool vis[MAX_N];
void pow(int *a, int y) {
    memset(vis, false, sizeof(vis));
    Rep(i, N) if (!vis[i]) {
        top = 0;
        for (int j = i; !vis[j]; j = a[j]) {
            vis[j] = true;
            st[++top] = j;
        }
        Rep(i, top) pos[st[i]] = i;
        int z = y % top;
        for (int j = i; ; j = a[j]) {
            ans[j] = st[(pos[a[j]] + z - 1) % top + 1];
            if (j == st[top]) break;
        }
        // Rep(i, top) {
            // ans[st[(i + z - 1) % top + 1]] = st[i];
        // }
    }
    Rep(i, N) a[i] = ans[i];
}

int main() {
    read(N), read(K);
    Rep(i, N) read(p[i]), a[1][i] = p[i];
    Rep(i, N) read(q[i]), a[2][i] = q[i];
    rep(i, 3, 6) {
        getinv(a[i - 2], inv);
        mul(a[i - 1], inv, a[i]);
    }
    if (K <= 6) {
        Rep(i, N) printf("%d ", a[K][i]); puts("");
        return 0;
    }
    getinv(p, inv);
    mul(q, inv, tmp2);
    getinv(q, inv);
    mul(inv, p, tmp3);
    mul(tmp2, tmp3, f);
    getinv(f, tmp);
    // Rep(i, N) debug("%d ", tmp[i]); dputs("");
    pow(f, (K - 1) / 6 - 1);
    pow(tmp, (K - 1) / 6 - 1);
    // Rep(i, N) debug("%d ", tmp[i]); dputs("");
    // debug("%d\n", K - (K - 1) / 6 * 6);
    mul(f, a[K - (K - 1) / 6 * 6], tmp2);
    mul(tmp2, tmp, res);
    Rep(i, N) printf("%d ", res[i]); puts("");
    return 0;
}


Measured memory_bytes: 10420