#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
char arr[2][210];
int key[210];
int round[210];
int block;
int k;
int main()
{
// freopen("in","rw",stdin);
while(cin>>block){
if(block==0)
break;
for(int i=0;i<block;++i)
cin>>key[i];
for(int i=0;i<block;++i){
int count =0;
int index=i;
while(++count){
index=key[index];
index--;
if(index==i)
break;
}
round[i]=count;
}
while(cin>>k){
if(k==0)
break;
getchar();
cin.getline(arr[0],block+1);
int len = strlen(arr[0]);
for(int j=len;j<block;++j)
arr[0][j]=' ';
arr[1][block]=NULL;
for(int j=0;j<block;++j){
int cnt = k%round[j];
int index=j;
for(int t=0;t<cnt;++t){
index = key[index];
index--;
}
arr[1][index]=arr[0][j];
}
cout<<arr[1]<<endl;
}
cout<<endl;
}
return 0;
}
|