#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define MAX 100000

typedef struct{
    char name[10];
    int num;
} que;

que Q[MAX];
int head = 0;
int tail = 0;

int isEmpty();
int isFull();
void enque(char *,int);
void deque();

int main(){
    int n,q,i,number,time = 0;
    char Name[10];

    scanf("%d%d",&n,&q);
    if(1 > n || n > 100000) exit(3);
    if(1 > q || q > 1000) exit(4);

    for(i = 0;i < n;i++){
        scanf("%s%d",Name,&number);
        if(1 > number || number > 50000) exit(5);

        enque(Name,number);
    }
    while(isEmpty() != 1){
        if(Q[head].num <= q){
            time += Q[head].num;
            if(1 > time || time > 1000000) exit(6);
            printf("%s %d\n",Q[head].name,time);
            deque();
        }
        else{
            Q[head].num -= q;
            time += q;
            if(1 > time || time > 1000000) exit(6);
            enque(Q[head].name,Q[head].num);
            deque();
        }
    }

    return 0;
}

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

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

void enque(char *naame,int x){
    if(isFull() == 1){
        printf("que is full\n");
        exit(1);
    }
    strcpy(Q[tail].name,naame);
    Q[tail].num = x;

    if(tail + 1 == MAX) tail = 0;
    else tail++;
}

void deque(){
    if(isEmpty() == 1){
        printf("que is empty\n");
        exit(2);
    }
    if(head + 1 == MAX) head = 0;
    else head++;
}
