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

int head,tail;

struct prosess{
  char name[100];
  int time;
};

struct prosess Queue[100000];

void enqueue(struct prosess x){
  Queue[tail]=x;
  tail=(tail+1)%100000;
}

struct prosess dequeue(){
  struct prosess x=Queue[head];
  head=(head+1)%100000;
  return x;
}

int min(int a,int b){
  return a<b ? a:b;
}

int main(){
  int elaps=0,c;
  int n,q,i;
  struct prosess u;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",Queue[i].name);
    scanf("%d",&Queue[i].time);
  }
  head=0;
  tail=n;
  while(head!=tail){
    u=dequeue();
    c=min(q,u.time);
    u.time-=c;
    elaps+=c;
    if(u.time>0){
      enqueue(u);
    }
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}
  
    

