#include <stdio.h>
#include <stdlib.h>
#define MAX 1000000

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

void enqueue(element);
element dequeue(void);

element queue[MAX];
int head,tail;

int main(){
    int i,n,q,ac=0,t;
    element e[n];
    element s;
    scanf("%d %d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s",queue[i].name);
        scanf("%d",&queue[i].time);
    }
    head=0;
    tail=n;
    while(head!=tail){
        s=dequeue();
        t=s.time-q;
        if(t>0){
            s.time=t;
            enqueue(s);
            ac=ac+q;
        }
        else {
            ac=ac+s.time;
            printf("%s %d\n",s.name,ac);

        }
    }
    return 0;

}
//データ挿入
 void enqueue(element x){
     int next=(tail+1)%MAX;
     queue[tail] = x;
    tail=next;
   
 }
 
//データ取り出し
 element dequeue(void){
    element x;
   x = queue[head];
   head=(head+1)%MAX;
  return x;
 }
