#include <stdio.h>
#include <assert.h>

#define MAX_NAME 10
#define MAX_N 100000
#define MOD 100000

typedef struct{
  char name[MAX_NAME+1];
  int _time;
} Data;

typedef struct{
  int head,tail;
  Data data[MAX_N];
} Queue;

void init(Queue*);
int isEmpty(Queue*);
void push(Queue*,Data);
Data pop(Queue*);

int main(){
  int N,Q,i,total = 0;
  Data data;
  Queue queue;
  scanf("%d %d",&N, &Q);
  for(i = 0 ; i < N ; i++){
    scanf("%s %d",data.name, &data._time);
    push(&queue,data);
  }
  while(!isEmpty(&queue)){
    data = pop(&queue);
    data._time -= Q;
    if(data._time > 0){
      total += Q;
      push(&queue,data);
    }else{
      total += data._time + Q;
      printf("%s %d\n", data.name, total);
    }
  }
  return 0;
}

void init(Queue *q){
  q->head = q->tail = 0;
}

int isEmpty(Queue *q){
  return (q->head == q->tail);
}

void push(Queue *q,Data d){
  q->data[(q->tail++)%MOD] = d;
}

Data pop(Queue *q){
  if(isEmpty(q)){
    assert(0);
  }
  return q->data[(q->head++)%MOD];
}