#include<iostream>
#include<queue>
using namespace std;
int main() {
ios::sync_with_stdio(false);//避免输入输出超时
cin.tie(0);
int n,m,t;
queue<string> q;
cin>>n>>m>>t;
string name;
string T;
int flag=0;
for(int i=0;i<n;i++){// 输入n个人的姓名
cin>>name;
q.push(name);
}
for(int j=1;j<m;j++){ //将第m个人放在队首
T=q.front();
q.push(T);
q.pop();
}
while(q.size()>1){
int temp=t;
flag=0;
while(temp>0){
if(temp%10==7||t%7==0){
q.pop();
flag=1;
break;
}
temp=temp/10;
}
if(flag==0){
T=q.front();
q.push(T);
q.pop();
}
t++;
}
cout<<q.front()<<"\n";
return 0;
}