#include <stdio.h>
#define MAX 100000

typedef struct{
  char name[10];
  int time;
}Queue;
Queue queue[MAX];

void enqueue(Queue);
Queue dequeue();
int isEmpty();
int isFull();

int head,tail;

int main(){
  int n,q,i,sum=0;
  Queue Q;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s%d",Q.name,&Q.time);
    enqueue(Q);
  }
  while(head!=tail){
    Q=dequeue();
    if( Q.time > q ){
      sum+=q;
      Q.time-=q;
      enqueue(Q);
    }
    else{
      sum+=Q.time;
      printf("%s %d\n",Q.name,sum);
    }
  }
  return 0;
}
int isFull(){
  return head==(tail+1)%MAX;
}
int isEmpty(){
  return head==tail;
}
void enqueue(Queue x){
  if(isFull())fprintf(stderr,"overflow\n");
  queue[tail]=x;
  if(tail+1==MAX) tail=0;
  else tail++;
}

Queue dequeue(){
  Queue x;
  if(isEmpty())fprintf(stderr,"underflow\n");
  x=queue[head];
  if(head+1==MAX) head=0;
  else head++;
  return x;
}