#include<stdio.h>
#define MAX 100000
typedef struct{
    char name[100];
    int time;
} queue;
 
void enqu(queue);
queue dequ(void);
 
int head=0,tail=0;
queue C[MAX];
 
    main(){
    int n,m,i,sum=0;
    queue D;

    scanf("%d%d",&n,&m);
        for(i=0;i<n;i++){
            scanf("%s%d",D.name,&D.time);
            enqu(D);
        }
        while(1){
            if(head == tail) break;
            if(D[head].time > m){
                m = dequ();
                D.time -= C;
                enqu(D);
                sum += m;
            }
            else{
                D = dequeue();
                printf("%s %d\n",D.name,D.time+sum);
                sum += D.time;
            }
        }
return 0;
}
 
void enqu(queue p){
C[tail] = p;
if(tail+1 == MAX) tail = 0;
else tail++;
}
 
queue dequ(){
    queue x;
    x = C[head];
 
    if(head+1 == MAX) head = 0;
    else head++;
    return x;
}