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

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

P Q[LEN+1];
P R[LEN+1];
int head=0, tail=0,n;

void enqueue(P);

void dequeue(P);

int main(){
  int elaps =0,k=0;
  int i,q,y;
  P u;
  scanf("%d %d", &n, &q);

  for(i=0;i<n;i++){
    scanf("%s %d",Q[i].name ,&Q[i].t);
    enqueue(Q[i]);
  }
  

  while(1){
    y=Q[head].t;
    u=Q[head];
    u.t-=q;
    
    if(u.t>0) enqueue(Q[tail]);
    else {strcpy(R[k].name,u.name);
      R[k].t = y + elaps*q;
      k++;}
     dequeue(Q[head]);
    elaps++;
    if(head==tail) break;
  }
    for(i=0;i<n;i++){
      printf("%s %d\n",R[i].name, R[i].t);
      }

  return 0;
}

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

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