#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int st[83][83];
int main()
{
int n;
__int64 m;
while(scanf("%d%I64d",&n,&m) != EOF)
{
if(n == 0 && m == 0)
break;
int i,j,pp;
char str[90],temp[83];
int sh[83],xia[83];
for(i = 0;i < n;i++)
{
scanf("%d",&pp);
pp--;
sh[i] = pp;
xia[pp] = i;//
}
getchar();
cin.getline(str,82,'\n');
for(i = 0; i < n;i++)
{
j = xia[i];
pp = 1;
while(i != j)
{
st[i][pp++] = j;
j = xia[j];
}
st[i][pp] = st[i][pp+1] = j;
st[i][0] = pp;//循环次数
}
for(i = 0; i < n;i++)
{
if(m % st[i][0] == 0)
pp = st[i][0];
else
{
pp = m % st[i][0];
pp = st[i][0] - pp;
}
temp [st[i][pp]] = str[i];
}
temp[n] = '\0';
printf("%s\n",temp);
}
return 0;
}