#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#define LEN 100005
#define MAX 100000    //?

typedef struct pp{
    char name[100];
    int t;
}P;

P Q[LEN+1];

int head, tail, n;
//int MAX;

void initialize(){
    head = tail = 0;
}

int isEmpty(){
    if(head == tail) return 1;
    else return 0;
}

int isFull(){
    if(head == (tail + 1) % MAX) return 1;
    else return 0;
}

void enqueue(P x){
    if(isFull()) printf("エラー（オーバーフロー）");
    Q[tail] = x;
    if(tail + 1 == MAX){
        tail = 0;
    }else{
        tail++;
    }
}

P dequeue(){
    P x;
    if(isEmpty()) printf("エラー（アンダーフロー）");
    x = Q[head];
    if(head + 1 == MAX){
        head = 0;
    }else{
        head++;
    }
    return x;
}


int main(){
    initialize();
    int elaps = 0, c; //elaps:時の経過
    int i, q;
    P u;
    
    scanf("%d %d", &n, &q);
    for (i=1; i<=n; i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
        enqueue(Q[i]);
    }
    //MAX=n;
    
    while(1){
        u = dequeue();
        if(q < u.t){
            elaps += q;
            u.t -= q; 
            enqueue(u);
        }else if(q >= u.t){// >=でないとダメ
            elaps += u.t;
            printf("%s %d\n", u.name, elaps);
        }
       // printf("%s %d\n", u.name, elaps);
        //if(Q[i].t == 0) printf("%s %d\n", u.name, elaps);
        if(isEmpty()) break;
    }
    return 0;
}
