#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define QSIZE 100000

typedef struct{
  char name[10];
  int time;
} DATA;

void enqueue(char *,int);
DATA dequeue(void);

DATA queue[QSIZE];
int head = 0;
int tail = 0;

int main(){
  int n,qtime,q,i,sam = 0;
  char str[10];
  DATA Via;

  scanf("%d%d",&n,&qtime);

  for(i = 0;i < n;i++){
    scanf("%s %d",str,&q);
    enqueue(str,q);
  }

  while(1){
    Via = dequeue();
    if((Via.time - qtime) <= 0){
      sam += Via.time;
      printf("%s %d\n",Via.name,sam);
    }

    else {
      sam += qtime;
      Via.time -= qtime;
      enqueue(Via.name,Via.time);
    }
    if(head == tail) break;
  }
  return 0;
}

void enqueue(char *str,int q){
  int next = (tail + 1) % QSIZE;

  if(head == next) exit(2);

  strcpy(queue[tail].name,str);
  queue[tail].time = q;

  tail = next;
}

DATA dequeue(){
  DATA Q;

  if(head == tail) exit(3);

  Q = queue[head];

  head = (head + 1) % QSIZE;

  return Q;
}

