#include<stdio.h>
#define L 100005

typedef struct{
  char pname[100];
  int time;
}EQ;

EQ eq[L];
int head, tail,n;

void enqueue(EQ a){
  eq[tail]=a;
  tail=(tail+1)%L;
}

EQ dequeue(){
  EQ a=eq[head];
  head=(head+1)%L;
  return 0;
}

int minjudge(int a,int b){
  if(a<b){return a;}
  else{return b}
}

int main(){

  int sumtime=0,add;
  int i,q;
  P ch;
  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d",eq[i].name,&eq[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    ch=dequeue();
    add=min(q,ch.time);
    ch.time-=add;
    sumtime+=add;
    if(ch.time>0)enqueue(ch);
    else{printf("%s %d\n",ch.pname,sumtime);}
  }
  return 0;
}




  
}

