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

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

static int head,tail;
process Q[MAX];

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

process dequeue(){
  process p = Q[head];
  head = (head+1) % MAX;
  return p;
}

int main(){
  int n,q,t=0,count=0;
  process p;
  scanf("%d %d",&n,&q);
  head=0; tail=0;
  for(int i=0; i<n; i++){
    scanf("%s %d",p.name,&p.time);
    enqueue(p);
  }
  while(count!=n){
    p = dequeue();
    if(p.time-q > 0){
      p.time -= q;
      t += q;
      enqueue(p);
    }
    else{
      t += p.time;
      count++;    
      printf("%s %d\n",p.name,t);
    }
  }
  return 0;
}