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

struct Process{
  char name[100];
  int t;
};
struct Process Q[1000];
int n;

void enqueue(struct Process x){
  int i;
	
  for(i=1;i<n;i++){
    Q[i]=Q[i+1];
  }
  Q[n]=x;
}

struct Process dequeue(){
  n--;
}

int main(){
  int i,q,m=0;
  scanf("%d %d",&n,&q);
	
  for (i=1;i<=n;i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
	
  while(1){
    if(n==0)break;
    if(Q[1].t>q){
      m+=q;
      Q[1].t-=q;
      enqueue(Q[1]);
    }
    else if(Q[1].t<=q){
      m+=Q[1].t;
      printf("%s %d\n",Q[1].name,m);
      enqueue(Q[1]);
      dequeue();
    }
  }
  return 0;
}