#include <stdio.h>
#include <stdlib.h>

#define N 100005
#define num 100
typedef struct aa
{
  char name[num];
  int t;
} A;

A data[N];
int head,tail,n;

void enqueue(A x){
data[tail]=x;
tail=(tail+1)%N;
}

A dequeue(){
A x=data[head];
head=(head+1)%N;
return x;
}

int min(int a,int b){return a<b?a:b;}

int main(){
int elaps=0,c;
int i,q;
A u;
scanf("%d %d",&n,&q);
for(i=1;i<=n;i++){
scanf("%s",data[i].name);
scanf("%d",&data[i].t);
}
head=1;
tail=n+1;

while(head!=tail){
u=dequeue();
c=min(q,u.t);
u.t-=c;
elaps+=c;

if(u.t>0){
enqueue(u);
}

else{
  printf("%s %d\n",u.name,elaps);
}
}

return 0;
}
