#include<stdio.h>
#define N 100000

typedef struct{
  char name[10];
  int time;
}P;

void enque(P);
P deque(void);

int head=0,tail=0,n;
P Q[N];

int main(){

  int p,i,cnt=0;
  P S[N],T;

  scanf("%d %d",&n,&p);

  for(i=0;i<n;i++){
    scanf("%s",S[i].name);
    scanf("%d",&S[i].time);
    enque(S[i]);
  }

  while(1){
    T=deque();
    T.time-=p;
    if(T.time>0){
      cnt+=p;
      enque(T);
    }else if(T.time<=0){
      cnt+=T.time+p;
      printf("%s %d\n",T.name,cnt);
      if (head == tail) break;
    }
  }

  return 0;
}

void enque(P x){
  tail = (tail+1)%N;
  Q[tail]=x;
}

P deque(){
  P x;

  head = (head+1)%N;
  x=Q[head];
  
  return x;
}

