#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct Data{
  char name[100];
  int t;
}data;

data Q[LEN+1];

int head,tail,n;

void enqueue(data x){
  Q[tail]=x;
  if(tail+1==LEN){
    tail=0;
  }
  else tail++;
}

data dequeue(){
  data x;
  x=Q[head];
  if(head+1==LEN)head=0;
  else head++;
  return x;
}

int main(){
  data a;
  int i,n,q,time=0;
  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s",a.name);
scanf("%d",&a.t);
enqueue(a);
}

while(head!=tail){
  a=dequeue();
  if(a.t>q){
    a.t=a.t-q;
    enqueue(a);
    time+=q;
  }
  else{
    printf("%s %d\n",a.name,a.t+time);
    time+=a.t;
  }
}
return 0;
}

