#include <stdio.h>
#include <string.h>
#define Max 10000000

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

int n, head = 0, tail = 0;
Data Q[Max];

void enqueue(Data);
Data dequeue(void);

int main(){
  int i, q, t = 0, count = 0;
  Data data;

  scanf("%d %d",&n, &q);
  for(i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
    enqueue(Q[i]);
  }
  while(count < n){
    data = dequeue();
    if(data.time <= q){
      t += data.time;
      count++;
      printf("%s %d\n",data.name, t);
    }
    else{
      t += q;
      data.time -= q;
      enqueue(data);
    }
  }
  
  return 0;
}

void enqueue(Data x){
  Q[tail] = x;
  if(tail + 1 == n) tail = 0;
  else tail++;
}

Data dequeue(void){
  Data x;
  x = Q[head];
  if(head + 1 == n) head = 0;
  else head++;
  return x;
}