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

#define N 100000

//node pointer
typedef struct DATA{
  char name[11];
  int time;
}DATA;

//prototype
void enqueue(DATA);
DATA *dequeue(void);

//Queue set
DATA Queue[N];

//head & tail & data number set
int head=0, tail=0, num;

int main(){
  int Q, i;
  DATA *data;

  //create *data
  data=(DATA *)malloc(sizeof(DATA));
  
  //input data number & Quantime
  scanf("%d %d",&num,&Q);

  //input data
  for(i=0;i<num;i++){
    scanf("%s %d",data->name,&data->time);
    enqueue(*data);
  }
  
  //count doing process time
  data=dequeue();
  i=0;
  while(data!=NULL){
    
    if(data->time<=Q){//finish process
      i+=data->time;
      
      printf("%s %d\n",data->name,i);
      data=dequeue();
    }

    else{//Quantime
      i+=Q;
      data->time-=Q;
      
      enqueue(*data);
      data=dequeue();
    }
    
  }

  
  return 0;
}


//input data to tail
void enqueue(DATA data){
  if(tail+1==head){//full
    printf("ERROR:full\n");
    exit(4);
  }

  Queue[tail]=data;
  tail++;
  if(tail==(num+1)) tail=0;
}


//output data from head
DATA *dequeue(void){
  DATA *dp;
  
  if(head==tail){//empty
    //printf("ERROR:empty\n");
    return NULL;
  }

  dp=&Queue[head];

  head++;
  if(head==(num+1)) head=0;
  return dp;
}

