//---include---
#include <stdio.h>
#include <string.h>

//---define----
#define LEN 200000

//---struct---
typedef struct pp{
  char name[100];
  int t;
}P;

//---function prototype declaration---
void enwueue(P);
P dequeue(void);
int isEmputy(void);
int isFull(void);
//---global arguments---
P Q[LEN+1];//プロセス名と処理時間の配列
int head=0;//キューの先頭
int tail=0;//キューの最後尾
int n;
//---function---
void enqueue(P x){
  if(isFull()){
  }else{
    Q[tail]=x;
    if(tail+1==LEN){
      tail=0;
    }else tail++;
  }
}
P dequeue(){
  P x;
  
  if(isEmpty()){
  }else{
    x = Q[head];
    if(head+1==LEN){
      head = 0;
    }else head++;
  }
  return x;
}
int isEmpty(){
  return head==tail;
}
int isFull(){
  return head == (tail+1)%LEN;
}
//---Main Function---
int main(){
  int elaps = 0, c;
  int flag=0;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);//プロセス数とクオンタイムの入力

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);//プロセス名
    scanf("%d", &Q[i].t);//処理時間
  }

  while(flag!=n){
    for(i=1; i<=n; i++){
      if(Q[i].t!=0){
	if((Q[i].t-q)<=0){
	  elaps+=Q[i].t;
	  printf("%s %d\n",Q[i].name, elaps);
	  flag++;
	  Q[i].t=0;
	}else{
	  elaps+=q;
	  Q[i].t=Q[i].t-q;
	}
      }
    }
  }
  return 0;
}

