// ${url}
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, [ next / $t:tt ]) => {
        {
            let len = read_value!($iter, usize);
            (0..len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
        }
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! ifv {
    ($t:expr, $a:expr, $b: expr) => {
        if $t { $a } else { $b }
    }
}

#[allow(unused_macros)]
macro_rules! fill {
    ($t:expr, $v:expr) => {
        for i in 0..$t.len() {
            $t[i] = $v;
        }
    };
}

#[allow(unused_macros)]
macro_rules! join {
    ($t:expr, $glue:expr) => {
        $t.into_iter().map(|w| w.to_string()).collect::<Vec<_>>().join($glue)
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn next(a: &Vec<usize>, b: &Vec<usize>) -> Vec<usize> {
    let mut c = a.clone();
    c.reverse();
    let al = a.len();
    for i in 0..al {
        c[i] ^= 1;
    }

    let bn = b.len();
    for i in 0..bn {
        let n = c.len();
        if c[n-1] ^ 1 == b[i] {
            c.pop();
        } else {
            c.push(b[i]);
        }
    }
    c
}

fn combine(a: &Vec<usize>, b: &Vec<usize>) -> Vec<usize> {
    let n = a.len();
    let mut c = vec![0; n];
    for i in 0..n {
        c[i] = b[a[i]];
    }
    c
}

fn pow(a: &Vec<usize>, mut p: i64) -> Vec<usize> {
    let n = a.len();
    let mut aa = a.clone();
    let mut ret = vec![0; n];
    for i in 0..n {
        ret[i] = i;
    }
    while p >= 1 {
        if p & 1 == 1 {
            ret = combine(&ret, &aa);
        }
        aa = combine(&aa, &aa);
        p >>= 1;
    }
    ret
}

fn inv(a: &Vec<usize>) -> Vec<usize> {
    let n = a.len();
    let mut ret = vec![0; n];
    for i in 0..n {
        ret[a[i]] = i;
    }
    ret
}

fn wl(a: &Vec<usize>, elements: &Vec<Vec<usize>>) -> Vec<usize> {
    let n = elements[0].len();
    let mut ret = vec![0; n];
    for i in 0..n {
        ret[i] = i;
    }
    for ai in a {
        ret = combine(&ret, &elements[*ai]);
    }
    ret
}

fn main() {
    input! {
        n: usize, k: usize,
        p: [usize1; n],
        q: [usize1; n]
    };

    let ip = inv(&p);
    let iq = inv(&q);

    let elements = vec![
        p.clone(),
        ip.clone(),
        q.clone(),
        iq.clone()
    ];

    let mut w = vec![];
    w.push(vec![]);
    w.push(vec![0]);
    w.push(vec![2]);
    for i in 3..20 {
        let z = next(&w[i-2], &w[i-1]);
        w.push(z.clone());
    }

    // a: [3, 0, 2, 1] i=8,14..
    // b: [0, 3, 1, 2] i=5,11,17

    let pa = wl(&vec![3, 0, 2, 1], &elements);
    let pb = wl(&vec![0, 3, 1, 2], &elements);

    let tbl = vec![
        vec![3, 0],
        vec![3, 0, 2],
        vec![2],
        vec![1, 2],
        vec![3, 1, 2],
        vec![3],
    ];

    let mut ans = vec![0; n];
    for i in 0..n {
        ans[i] = i;
    }
    if k <= 10 {
        let ln = w[k].len();
        for i in 0..ln {
            ans = combine(&ans, &elements[w[k][i]]);
        }
    } else {
        let cnt_a = (k-8)/6+1;
        ans = combine(&ans, &pow(&pa, cnt_a as i64));
        let md = k % 6;
        let p = wl(&tbl[md], &elements);
        ans = combine(&ans, &p);
        let cnt_b = (k-5)/6+1;
        ans = combine(&ans, &pow(&pb, cnt_b as i64));
    }
    for i in 0..n {
        ans[i] += 1;
    }
    println!("{}", join!(ans, " "));
}


Measured memory_bytes: 23880