#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

#define LEN 1000005

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

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
    
}

P dequeue(P que, int q){
    
    if (que.t - q <= 0) {
        que.t = 0;
    }else{
        que.t = que.t - q;
    }

    return que;
}


int main(){
    int elaps = 0, c = 0;
    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);
    }
    
    i = 1;
    while(1){
        
        u = dequeue(Q[i],q);
        if (u.t == 0) {
            c += Q[i].t;
            printf("%s ",Q[i].name);
            printf("%d\n",c);
            n--;
        }else{
            c += q;
            Q[i+n] = u;
        }
        
        if (n == 0)break;
        i++;
        
        
    }
    
    return 0;
}

