#include <stdio.h>
#include <string.h>
#define N 100

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

void enqueue(P);
P dequeue();
int min(int , int);

int head, tail, n;
P data[N];

int main(){
  int q, i;
  P ext;
  int little=0, spend;
  
scanf("%d%d", &n , &q);
 for(i=0;i<n;i++)scanf("%s%d", data[i].name, &data[i].time);

 head = 1;
 tail = n+1;
 
 while(head != tail){
   ext = dequeue();
   spend = min(q, ext.time);
   ext.time -= spend;
   little += spend;
   if(ext.time > 0)enqueue(ext);
   else printf("%s %d\n", ext.name, little);
 }
 
  return 0;
}

void enqueue(P eq){
  data[tail] = eq;
  tail = (tail+1) % N;
}

P dequeue(){
  P eq = data[head];
  head = (head+1) % N;
  return eq;
}

int min(int a, int b){
  return a < b ? a : b;

}

