#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    // let mut a = vec![0];
    // let mut b = vec![1];

    // for i in 0..100 {
    //     println!("{}: {:?}", i, a);

    //     let mut c = b.clone();
    //     for &x in a.iter().rev() {
    //         if c.last().cloned() == Some(x) {
    //             c.pop();
    //         } else {
    //             c.push(x ^ 2);
    //         }
    //     }

    //     a = b;
    //     b = c;
    // }
    // return;

    input! {
        n: usize,
        k: usize1,
        p: [usize1; n],
        q: [usize1; n],
    }

    // 6:  [1, 2, 3, 0, 1, 0, 3]
    // 7:  [1, 2, 3, 0, 1, 2, 1, 0, 3]
    // 8:  [1, 2, 3, 0, 1, 2, 2, 1, 0, 3]
    // 9:  [1, 2, 3, 0, 1, 2, 3, 2, 1, 0, 3]
    // 10: [1, 2, 3, 0, 1, 2, 3, 0, 3, 2, 1, 0, 3]
    // 11: [1, 2, 3, 0, 1, 2, 3, 0, 0, 3, 2, 1, 0, 3]

    // 12: [1, 2, 3, 0, 1, 2, 3, 0, 1, 0, 3, 2, 1, 0, 3]
    // 13: [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 1, 0, 3, 2, 1, 0, 3]
    // 14: [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 2, 1, 0, 3, 2, 1, 0, 3]
    // 15: [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 2, 1, 0, 3, 2, 1, 0, 3]
    // 16: [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3]
    // 17: [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0, 0, 3, 2, 1, 0, 3, 2, 1, 0, 3]

    let mut a = vec![vec![0; n]; 4];
    for i in 0..n {
        a[0][i] = p[i];
    }
    for i in 0..n {
        a[1][i] = q[i];
    }
    a[2] = inv(&a[0]);
    a[3] = inv(&a[1]);

    let m = if k < 6 {
        let tbl: &[&[usize]] = &[
            &[0],
            &[1],
            &[1, 2],
            &[1, 2, 3],
            &[1, 2, 3, 0, 3],
            &[1, 2, 3, 0, 0, 3],
        ];

        let mut m = id(n);
        for &aix in tbl[k].iter() {
            m = mulv(&m, &a[aix]);
        }
        m
    } else {
        let tbl: &[&[usize]] = &[
            &[1, 0, 3],
            &[1, 2, 1, 0, 3],
            &[1, 2, 2, 1, 0, 3],
            &[1, 2, 3, 2, 1, 0, 3],
            &[1, 2, 3, 0, 3, 2, 1, 0, 3],
            &[1, 2, 3, 0, 0, 3, 2, 1, 0, 3],
        ];

        let t = mulv(&a[1], &mulv(&a[2], &mulv(&a[3], &a[0])));
        let u = mulv(&a[2], &mulv(&a[1], &mulv(&a[0], &a[3])));

        let mut m = powv(&t, k / 6);
        for &aix in tbl[k % 6].iter() {
            m = mulv(&m, &a[aix]);
        }
        m = mulv(&m, &powv(&u, k / 6 - 1));
        m
    };

    // dbg!(&m);

    for (i, x) in m.into_iter().enumerate() {
        if i > 0 {
            print!(" ");
        }
        print!("{}", x + 1);
    }
    println!();
}

fn id(n: usize) -> Vec<usize> {
    (0..n).collect()
}

fn mulv(p: &Vec<usize>, q: &Vec<usize>) -> Vec<usize> {
    let mut v = vec![0; p.len()];
    for i in 0..p.len() {
        v[i] = p[q[i]];
    }
    v
}

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

fn powv(v: &Vec<usize>, n: usize) -> Vec<usize> {
    if n == 0 {
        return id(v.len());
    } else if n == 1 {
        return v.clone();
    }

    let m = n / 2;
    let mut w = powv(&mulv(v, v), m);
    if n % 2 == 1 {
        w = mulv(&w, v);
    }
    w
}


Measured memory_bytes: 42396