#include<stdio.h>
#include<stdlib.h>

#define N 100000

int head=0,tail=0;
int Qi[N];
char Qc[N][10];

void enq(char *s,int x){
  int i=0;
  if(isFull()){
    fprintf(stderr,"over flow\n");
    exit(1);
  }
  Qi[tail] = x;
  while(Qc[tail][i]=s[i]){
    i++;
  }
  if(tail+1 == N){
    tail = 0;
  }else{
    
    tail++;
  }
}

int deq(){
  int x;
  if(isEmpty()){
    fprintf(stderr,"empty\n");
    exit(2);
  }
  x = head;
  if(head + 1 == N){
    head = 0;
  }else{
    head++;
  }
  return x;
}

int isEmpty(){
  return head == tail;
}

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

void roundschedule(int n,int q){
  int i,num,sum=0,over;
  char name[10];
  for(i=0;i<n;i++){
    scanf("%s ",name);
    scanf("%d",&num);
    enq(name,num);
  }
 
  while(!isEmpty()){
     num=deq();
    if(q>=Qi[num]){
      sum+=Qi[num];
      printf("%s %d\n",Qc[num],sum);
    }else{
      over=Qi[num]-q;
      sum+=q;
      enq(Qc[num],over);
    }

  }
}

int main(){
  int n,q;
  scanf("%d%d",&n,&q);
  roundschedule(n,q);
  return 0;
}

