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

#define MAX 100000
#define true 1
#define false 0

typedef struct{
  char name[11];
  int time;
}Process;

void initialize(void);
int isEmpty(void);
int isFull(void);

int head,tail;
Process Q[MAX];



void initialize(){
  head = tail = 0;
}

void enqueue(Process x){
  if(isFull() == true) exit(1);
  Q[tail] = x;
  if(tail + 1 == MAX)
    tail = 0;
  else{
    tail++;
    
  }
}

Process dequeue(){
  Process x;
  if(isEmpty() == true) exit(1);
  x = Q[head]; 
  if(head + 1 == MAX)
    head = 0;  
  else{
    head++;
  }
  return x;
}

int main(){
  int elaps = 0;
  int i,q,n;
  Process u;

  initialize();
  
  scanf("%d%d",&n,&q);
  
  for(i=0 ; i<n ; i++){
    scanf("%s%d",Q[i].name,&Q[i].time);

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



int isEmpty(void){
  if(head == tail) return true;
  return false;
}

int isFull(void){
  if(head == (tail + 1) % MAX) return true;
  return false;
}
  


