#include <stdio.h>
#include <string.h>
#define M 100005

typedef struct QQ{
    char name[100];
    int t;
}Q;

Q proc[M];
int head,tail;

void enqu(char name[100], int t){
    strcpy(proc[tail].name,name);
    proc[tail].t = t;
    tail = (tail + 1) % M;
}

void robbin(int waste,int n){
   int time=0,ct=0;
   while(head!=tail){
       if(waste < proc[head].t){
           time += waste;
           proc[head].t -= waste;
           enqu(proc[head].name,proc[head].t);
       }
       else {
           time += proc[head].t;
           printf("%s %d\n",proc[head].name,time);
       }
       head= (head + 1 )% M;
   }
}

int main(void){
    head=0;
    int n,waste,i,t;
    char name[100];
    scanf("%d%d",&n,&waste);
    tail = 0;
    for(i=0;i<n;i++){
        scanf("%s%d",name,&t);
        enqu(name,t);
    }
    robbin(waste,n);
    return 0;
}

