#include <iostream>
#include <stdio.h>
#include <string.h>

#define len 100005

typedef struct pp{
    char name[100];
    int time;
}p;

p queue[len];
int head,tail;

void enqueue(p n){
    queue[tail]=n;
    tail=(tail+1)%len;
}

p dequeue(){
     p v=queue[head];
    head=(head+1)%len;
    return v;
}

int min(int a,int b){
    return a<b?a:b;
}

int main() {
    int n,t,i,c;
    int sum=0;
    p u;
    scanf("%d %d",&n,&t);
    for (i = 1; i <= n; ++i) {
        scanf("%s",queue[i].name);
        scanf("%d",&queue[i].time);
    }

    head=1;
    tail=n+1;

    while(head!=tail){
        //????????????,?????´??????
        u=dequeue();
        c=min(u.time,t);
        //??????????????¶??´
        sum+=c;
        //??´??°????¨???¶??´
        u.time-=c;
        if(u.time>0){
            enqueue(u);
        } else{
            printf("%s %d\n",u.name,sum);
        }
    }

    return 0;
}