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

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

typedef struct {
    int front, rear, queue_size;
    process_t *elements;
} queue;

void SetProcess(process_t *p, char *name, int time){
    strcpy(p->name, name);
    p->time = time;
    return;
}

void InitQueue(queue *q, int ps){
    q->front = 0;
    q->rear = 0;
    q->queue_size = ps;
    return;
}

void Putq(queue *q, process_t p){
    q->elements[q->rear] = p;
    if(q->rear == q->queue_size){
        q->rear = 0;
    }
    else{
        q->rear += 1;
    }
    return;
}

process_t Getq(queue *q){
    process_t p;
    p = q->elements[q->front];
    if(q->front == q->queue_size){
        q->front = 0;
    }
    else{
        q->front += 1;
    }
return p;
}

int QueueEmpty(queue *q){
return (q->front == q->rear);
}

int main(){
int i;
int ps,quantum,time,total_time;
char name[10];
process_t process;
queue q;


scanf("%d %d", &ps, &quantum);
InitQueue(&q, ps);
q.elements = (process_t *)malloc(sizeof(process_t)*(ps+1));
for(i = 0; i < ps; i++){
  scanf("%s %d", name, &time);
  SetProcess(&process, name, time);
  Putq(&q, process);
}


while(!QueueEmpty(&q)){
  process = Getq(&q);
  if(process.time <= quantum){
      total_time += process.time;
      printf("%s %d\n", process.name, total_time);
  }
  else{
      process.time -= quantum;
      total_time += quantum;
      Putq(&q, process);
  }
}

free(q.elements);
return 0;
}

