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

#define MAX 1000000
struct unk{
   int time;
   char name[10];
} ;

void intialize();
int isEmpty();
int isFull();
void enqueue(struct unk);
struct unk dequeue();

int head,tail;

struct unk Q[MAX];
struct unk A[MAX];

int main(){
    int n,q,i,sum=0;
    struct unk a;
    scanf("%d%d",&n,&q);

    for(i=0;i<n;i++){
        scanf("%s%d",A[i].name,&A[i].time);
        enqueue(A[i]);
    }

    while(isEmpty()-1){
        a = dequeue();
     
    if(a.time<=q){
               sum += a.time;
              
               printf("%s %d\n",a.name,sum);
        }

        else{
            a.time = a.time -q;
            enqueue(a);
            sum += q;
        }
   
    }
     
     return 0;

}



void intialize()
{
    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(struct unk x){
     if (isFull())
    {
        printf("エラー\n");
    }
    Q[tail] = x;
    if( tail +1 == MAX){
        tail = 0;
    }

    else{
        tail++;
    }
}

struct unk dequeue(){
    struct unk x;
    if (isEmpty())
    {
        printf("エラー\n");
    }

    x = Q[head];
    if(head +1==MAX){
        head = 0;
    }

    else {
        head++;
    }

    return x;
}
