#include<stdio.h>
#include <string.h>
#include<stdlib.h>
#define MAX 1000000

typedef struct{
  char name[100];
  int t;
}Data;

void enqueue(Data);
Data dequeue(void);
int isEmpty(void);
int isFull(void);
int min(int,int);

Data Q[MAX];
int head=0,tail=0;

int main(){
  Data num;
  int n,q,time=0,i;

  scanf("%d%d",&n,&q);

  for(i=0;i<n;i++){
      scanf("%s%d",num.name,&num.t);
     enqueue(num);
  }
   

   while(1){
     num=dequeue();
     n=strcmp(num.name,"NULL");
     if(n==0)
     break;

     n=min(q,num.t);
     num.t -=n;
     time += n;
     if(num.t>0){
         enqueue(num);
     } else{
       printf("%s %d\n",num.name,time);
     }
   }

  return 0;
}


void enqueue(Data da){
    if(isFull()==1)
    exit(1);
  Q[tail]=da;
   tail=(tail+1)%MAX;
}

Data dequeue(void){
    Data num;
     if(isEmpty()==1){
         strcpy(num.name,"NULL");
         num.t=10000;
         return num;
     }
    num=Q[head];
    head=(head+1)%MAX;
  return num;
}

int isEmpty(void){
  if(head==tail) return 1;
  else return 0;
}

int isFull(void){
  if(head==(tail+1)%MAX)return 1;
  else return 0;
}

int min(int x,int y){
    return x<y ? x : y;
}
