#include<stdio.h>
#include<string.h>
#define N 100005
 
typedef struct p{
  char name[100];
  int t;
}P;
 
P Q[N+1];
int top, tail, n;
P temp;
 
void enqueue(P x){ //push
  Q[tail]=x;
  if(tail==N)
    tail=1;
  else
    tail++;
}
 
P dequeue(){ //pop
  P x;
  x=Q[top];
   
  if(top==N)
    top=1;
  else
    top++;
  return x;
}
 
 
int main(){
  int elaps = 0, c;
  int i, q,remain,total;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
 
  top=1;
  tail=n+1;
 
  while(top!=tail){
    temp=dequeue();
    remain=temp.t-q;
    if(remain>0) {
      total+=q;
      temp.t=remain;
      enqueue(temp);
    }
    else {
      total+=temp.t;
      printf("%s %d\n",temp.name,total);
    }
 
  }
    return 0;
}