#include <stdio.h>
#include <string.h>
#define LEN 100005
#define MAX 1000
typedef struct pp{
  char name[100];
  int t;
}P;
int isEmpty();
void initialize();
int isFull();
void enqueue(P);
P dequeue();
int min(int, int);

int head,tail,n;/*globl avairable*/

 P Q[LEN+1];

int main(){
  int time = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head = 1;
  tail = n + 1;

  while(head != tail){
    u = dequeue();
    c = min(q, u.t);
    u.t -= c;
    time += c;
    if(u.t > 0){
      enqueue(u);
    } else {
      printf("%s %d\n",u.name,time);
    }
  }
  return 0;
}
void initialize(){
  head = 0;
  tail = 0;
}
int isEmpty(){
  return head == tail;
}
int isFull(){
  return head == (tail + 1) % MAX;
}
void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
  if(isFull()){
    /*error over flow*/
  }
  Q[tail] = x;
  if(tail + 1 == MAX){
    tail = 0;
  } else {
    tail++;
  }
}

P dequeue(){
  P x;
  /*
  head = (head + 1) % LEN;
  return x;
  */
  if(isEmpty()){
    /*error under fllow*/
  }
  x = Q[head];
  if(head + 1 == MAX){
    head = 0;
  }else{
    head++;
  }
  return x;
}
int min(int x, int y){
  return x < y;
}