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

typedef struct a{
    char name[100];
    int x;
}P;
P c[A];
int head,tail,n;

void enqueue(P p){
    c[tail]=p;
    tail=(tail+1)%A;
} 
P dequeue(){
    P x=c[head];
    head=(head+1)%A;
    return x;
}
int minimum(int a,int b){return a<b ? a: b;}
int main (){
    int m=0,d,i,j;
    P u;
    scanf("%d %d",&n,&j);
for(i=1;i<=n;i++){
    scanf("%s",c[i].name);
    scanf("%d",&c[i].x);
}
head=1;
tail=n+1;
while(head!=tail){
    u=dequeue();
    d=minimum(j,u.x);
    u.x-=d;
    m+=d;
    if(u.x>0)enqueue(u);
    else{
        printf("%s %d\n",u.name,m);
    }
}
return 0;
}
