#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 100005

typedef struct{
  char name[100];
  int time;
}Array;


void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(Array );
Array dequeue(void);

int head;
int tail;
int MAX = 100;
Array array[LEN+1];
int main(){
  Array hrt;
  int n;
  int q;
  int i=0;
  int timecount=0;

  initialize();
  scanf("%d%d",&n,&q);//個数の入力

  while(i < n){//中身の入力
    scanf("%s %d",hrt.name, &hrt.time);
    enqueue(hrt);
    i++;
  }
  while(head!=tail){//headとtailが同じの場所のとき終了
    hrt = dequeue();//hrtには先頭の値
    if(hrt.time <= q){//timeが 0 になったもの
      timecount += hrt.time;
      printf("%s %d\n",hrt.name,timecount);
    }
    else{ //残りのtime
      timecount += q;//timeを足す
      hrt.time -= q;//実行したtime分減らす
      enqueue(hrt);//一番後ろに格納
    }
  }
  return 0;
}


void initialize(void){//headとtailの初期化
  head = tail = 0;
}

int isEmpty(void){ //headとtailが同じなら中身は空
  return head == tail;
}

int isFull(void){//中身がいっぱい
  return head == (tail+1)%MAX;
}

void enqueue(Array x){
  if(isFull()){
    printf("Error1\n");
    exit(1);
  }
  array[tail] = x;
  if(tail + 1 == LEN+1){
    tail = 0;
  }
  else{
    tail++;
  }
}

Array dequeue(void){
  Array x;

  if(isEmpty()){
      printf("Error2\n");
      exit(2);
    }
  x = array[head];
  if(head + 1 == LEN+1){
    head = 0;
  }
  else{
    head++;
  }
  return x;//先頭の中身を返す
}