#include<bits/stdc++.h>
using namespace std;
vector<string>p;
bool flag(int t){
while(t!=0){
if(t%10==7)return true;
t/=10;
}
return false;
}
int main(){
string a=" ";
p.push_back(a);
int n,m,t;
cin>>n>>m>>t;
while(n--){
string name;
cin>>name;
p.push_back(name);
}
vector<string>::iterator it;
while(p.size()!=2){
if(t%7==0||flag(t)){
if(m==p.size()-1){
p.erase(p.begin()+m);
t++;
m=1;
}else{
p.erase(p.begin()+m);
t++;
}
}else{
m++;
t++;
if(m>p.size()-1){
m=1;
}
}
}
cout<<p[1];
}