#include<stdio.h>
#include<stdlib.h>

#define MAX 100005

typedef struct{
  char name[10]; 
  int qtime;
  int endtime;
} Process;

Process Q[MAX];
int head=0,tail=0;
int time=0;

void enqueue(Process);
Process dequeue(void);

int main()
{
  int n,q; // n = プロセス数、 q = クオンタム
  int i,count=0;
  Process *P;
  Process *E;
  Process P1;

  //入力
  scanf("%d %d",&n,&q);
  P = (Process *)malloc( n * sizeof(Process));
  E = (Process *)malloc( n * sizeof(Process));
   
  for(i=0;i<n;i++){
    scanf("%s",P[i].name);
    scanf("%d",&P[i].qtime);
    enqueue(P[i]);
  }

  //処理
  while(head != tail){
    if(Q[head].qtime <= q){

      time += dequeue().qtime;
      Q[head-1].endtime = time;
      E[count] = Q[head-1];
      
      count++;
      
      //printf("1\n");
    }
    else {
      time += q;
      P1 = dequeue();
      P1.qtime -= q;
      enqueue(P1);
      //printf("0\n");
    }
  }

  for(i=0;i<count;i++){
    printf("%s %d\n",E[i].name,E[i].endtime);
  }
  return 0;
}

void enqueue(Process x)
{
  Q[tail] = x;
  tail=(tail+1)%MAX;
}

Process dequeue()
{
  Process x;
  x = Q[head];
  Q[head].qtime = 0;
  head=(head+1)%MAX;

  return x;
}

  

  


