#include <stdio.h>
#define MAXLENGTH_ARRAY 1000000
typedef struct
{
    char name[100];
    int time;
}Process;
Process p[MAXLENGTH_ARRAY];
int front,tail=0;
void InQ(Process new){p[tail++]=new;}
Process OutQ(){return p[front++];}
int main() {
    int n,q,duration=0;
    scanf("%d %d", &n, &q);
    for(int i=0;i<n;i++)
    {
        scanf("%s %d", p[i].name, &p[i].time);
    }
    tail = n;
    while(front!=tail)
    {
        Process x = OutQ();
        x.time-=q;
        if(x.time>0){InQ(x);duration +=q;}
        else{
                duration +=q + x.time;
                printf("%s %d\n", x.name, duration);
        }
    }
    return 0;
}


