#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int n, x[N], a[N];
ll k;
int Pow(int a, ll b){
if(b == 0) return a;
int res;
while(b){
if(b & 1) res = x[a];
a = x[x[a]];
b >>= 1;
}
return res;
}
int main(){
ios :: sync_with_stdio(false);
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> x[i];
for(int i = 1; i <= n; i++) cin >> a[i];
for(int i = 1; i <= n; i++)
cout << a[Pow(i, k)] << ' ';
return 0;
}
求调