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

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

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

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

int main(){
  int total = 0,min,i,qms;
  process stream;

  scanf("%d%d",&n,&qms);
  for(i = 0;i < n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
  }

  head = 0;
  tail = n;

  while(tail != head){
    stream = dequeue();
    if(qms > stream.time) min = stream.time;
    else min = qms;
    stream.time -= min;
    total += min;
    if(stream.time > 0) enqueue(stream);
    else printf("%s %d\n",stream.name,total);
  }
  
  return 0;
}

void enqueue(process x){
  if(isFull() == 1){
    printf("エラー（オーバーフロー）\n");
    exit(7);
  }
  Q[tail] = x;
  if((tail + 1) == MAX) tail = 0;
  else tail++;
}

process dequeue(){
  process x;
  if(isEmpty() == 1){
    printf("エラー（アンダーフロー）\n");
    exit(8);
  }
  x = Q[head];
  if((head + 1) == MAX) head = 0;
  else head++;
  return x;
}

void initialize(){
  head = tail = 0;
}

int isEmpty(){
  if(head == tail) return 1;
  else return 0;
}

int isFull(){
  if(head == (tail + 1) % MAX) return 1;
  else return 0;
}

