#include<stdio.h>
#define L 100000//キューの長さ

typedef struct{
  char name[11];
  int ms;
}Process;

Process A[L];
int head=0, tail=0;//head=tailで初期化出来る(空に出来る)////////////
/*
int isFull(){
  if(head == (tail+1)%L;
  return 1;
}
*/
int isEmpty(){//1なら空
  if(head==tail)return 1;
  return 0;
}


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

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


int main(){
  int i;
  int p_num,q_time;
  Process A;
  int total_time=0;
  
  scanf("%d%d", &p_num, &q_time);//INPUT
  for ( i = 0; i < p_num; i++){
    scanf("%s%d", A.name,&A.ms);
    enqueue(A);
  }

  while(isEmpty()==0){
    A=dequeue();
    A.ms-=q_time;

    if(A.ms>0){
      enqueue(A);
      total_time+=q_time;
    }
    else{//OUTPUT
      total_time+=q_time+A.ms;//20 -100のとき100-80でかかった時間
      printf("%s %d\n",A.name,total_time);
    }
  }    
  return 0;
}
/*
5 100　プロセス数　クオンタイム
p1 100
p2 100


プロセス完了順にかかった終了時刻
p2 180 
*/

