#include
#include
#include
#include
#include
#include
#include
#include
#define mem(a,x) memset(a,x,sizeof(a))
#define s1(x) scanf("%d",&x)
#define s2(x,y) scanf("%d%d",&x,&y)
#define s3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s4(x,y,z,k) scanf("%d%d%d%d",&x,&y,&z,&k)
#define ff(a,n) for(int i = 0 ; i < n; i++) scanf("%d",a+i)
#define tp(x) printf("x = %d\n",x)
#define ansp(x) printf("%d\n",x)
//inline ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&(-x);return res;}
//inline void add(int x,int d){while(x<=n)c[x]+=d,x+=x&(-x);}
#define ls 2*rt
#define rs 2*rt+1
#define lson ls,L,mid
#define rson rs,mid+1,R
#define ll long long
using namespace std;
typedef pair pii;
const ll inf = 0x3f3f3f3f;
const int antiprime[]={1,2,4,6,12,24,36,48,60,120,180,240,360,720,840,
1260,1680,2520,5040,7560,10080,15120,20160,25200,
27720,45360,50400,55440,83160,110880,166320,221760,
277200,332640,498960,554400,665280
};
const int factorNum[]={1,2,3,4,6,8,9,10,12,16,18,20,24,30,32,36,40,48,60,
64,72,80,84,90,96,100,108,120,128,144,160,168,180,
192,200,216,224};
const int mx = 5e5+10;
int node[mx<<2];
int n,k,pos,mod;
struct no{
char name[13];
int id;
}p[mx];
void build(int rt, int L, int R){
node[rt] = R-L+1;
if(L == R)
return;
int mid = (L+R)/2;
build(lson);
build(rson);
}
int update(int rt, int L, int R, int p){
node[rt]--;
if(L == R)
return L;
int mid = (L+R)/2;
if(p <= node[ls])
return update(lson, p);
else
return update(rson, p-node[ls]);
}
int main(){
//int T=10; scanf("%d",&T);
// freopen("F:\\in.txt","r",stdin);
while(s2(n,k) != EOF){
for(int i = 1; i <= n ; i++){
scanf("%s%d",p[i].name,&p[i].id);
}
int cnt = 0;
while(cnt<35&&antiprime[cnt] <= n)
cnt++;
cnt--;
p[0].id = 0;
pos = 0;
build(1,1,n); //忘了建树, ,,,,
for(int i = 0; i < antiprime[cnt]; i++){
mod = node[1]; //mod应该被更新的
if(p[pos].id > 0)
k = ((k+p[pos].id-2)%mod+mod)%mod+1; //错写成减号
else{
k = ((k+p[pos].id-1)%mod+mod)%mod+1;
}
pos = update(1,1,n,k);
}
printf("%s %d\n",p[pos].name,factorNum[cnt]);
}
return 0;
}