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

#define LL 100005

int head, tail, n;

typedef struct aa{
    char name[100];
    int ss;
}A;

A B[LL];

int min(int sss,int ttt){
    return sss<ttt?sss:ttt;
}

void enqueue(A s){
    B[tail] = s;
    tail = (tail+1)%LL;
}

A dequeue(){
    A s = B[head];
    head = (head+1)%LL;
    return s;
}

int main(){
    int elaps = 0;
    A m;
    int i, j, b;
    
    scanf("%d %d", &n, &j);
    for(i=1 ; i <= n ; i++){
        scanf("%s", B[i].name);
        scanf("%d",&B[i].ss);
    }
    
    tail = n+1;
    head = 1;
    
    while(head!=tail){
        m = dequeue();
        b = min(j,m.ss);
        m.ss -= b;
        elaps += b;
        
        if(m.ss>0){
            enqueue(m);
        }else{
            printf("%s %d\n", m.name, elaps);
        }   
    }
    
    return 0;
    
}
