#include<stdio.h>
#define LEN 100005

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

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

void enqueue(P x){
  int next=(tail+1)%LEN;

  Q[tail]=x;
  tail=next;
}

P dequeue(){
  P val;

  val=Q[head];
  head=(head+1)%LEN;
  return val;
}

int min(int q,int x){
  if(q<x) return q;
  else return x;
}

int main(){
  P ori; 
  int i,q,j,keika=0,t;

  scanf("%d%d",&n,&q);
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head=1;
  tail=n+1;

  while(head!=tail){
      ori=dequeue();
      t=min(q,ori.t);
      ori.t-=t;
      keika+=t;
      if(ori.t>0) enqueue(ori);
      else {
	printf("%s",ori.name);
	printf("%c",' ');
	printf("%d\n",keika);
      }
  }
  
  return 0;
}



