#include <stdio.h>
#define MAX 100000

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

void enqueue(Q);
Q dequeue();
int head=0;
int tail=0;
Q data[MAX];

int main(){
    int n,q;
    Q x;
    int i,all=0;
    scanf("%d%d",&n,&q);
    for(i=0;i<n;i++){
        scanf("%s%d",x.name,&x.time);
        x.sum=0;
        enqueue(x);
    }
    //printf("\n");
    while(head!=tail){
        x=dequeue();
        if(x.time-q>0){
            x.time-=q;
            all+=q;
            enqueue(x);
        }else{
            all+=x.time;
            x.sum+=all;
            printf("%s %d\n",x.name,x.sum);
        }
    }
    return 0;

    
}

void enqueue(Q x){
    data[tail]=x;
    if(tail+1==MAX)tail=0;
    else tail++;
}

Q dequeue(){
    Q x;
    x=data[head];
    if(head+1==MAX)head=0;
    else head++;
    return x;
}