#include<stdio.h>
#include<stdlib.h>
#define N 100005

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

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P);
P dequeue(void);

int TIME=0;

P Q[N+1];
int head,tail,n;

int main(){
  int elaps=0,c;
  int i,q;
  P u;
  initialize();
  scanf("%d%d",&n,&q);//プロセス数とクオンタムの入力
  for(i=1;i<=n;i++){
    scanf("%s",u.name);
    scanf("%d",&u.t);
    enqueue(u);
  }
  
  while(isEmpty()!=1){
    u=dequeue();
      if (u.t<=q){
	TIME=TIME+u.t;
	printf("%s %d\n",u.name,TIME);

      }
      
      else{
	TIME=TIME+q;
	u.t=u.t-q;
	enqueue(u);
      }
      
    }
    
  
  
  return 0;
}

void initialize(){
  head=1;
  tail=1;
}

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

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

void enqueue(P x){
  if(isFull()==1){
    printf("Queue is Full\n");
    exit(1);
  }
  Q[tail]=x;
  if((tail+1)==N)
    tail=1;
  else tail++;
}

P dequeue(){
  P x;
  if (isEmpty()==1){
    printf("Queue is Empty\n");
    exit(2);
  }
  x=Q[head];
  if((head+1)==N)
    head=1;
  else head++;
  return x;
}

