#include<stdio.h>
#include<string.h>
typedef struct  {
  char name[100];
  int t;
  
} P;
P Q[100000];
int head,tail,n;
void initialize(){
  head=0;
    tail=0;
}
int isEmpty(){
  if(head==tail){
    return ;
  }
}
void enqueue(P x){
  if (isFull()){
    fprintf(stderr,"Overflow");
  }
 


  Q[tail]=x;
  if(tail+1==100000){
    tail=0;
  }
  else tail++;
}

P dequeue(){
  if (isEmpty){
    fprintf(stderr,"Underflow");
  }
  P x=Q[head];
  if(head+1==100000){
    head=0;
  }
  else head++;
  return x;
  
}
int min(int a,int b){
  return a<b ? a:b;
}
int main(){
  int L=0,c;
  int i,q;
  P a;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",&Q[i+1].name);
    scanf("%d",&Q[i+1].t);
  }

head=1;
tail=n+1;
while(head!=tail){
  a=dequeue();
  c=min(q,a.t);
  a.t=a.t-c;
  L=L+c;
  if(a.t>0)enqueue(a);
  else{
    printf("%s %d",a.name,L);
  }
 }
 return 0;
 
}
  