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


typedef struct
{
    char name[10];
    int quantum;
}Task;

int enqueue (Task a,int tail,int size, Task *task);
Task dequeue (int head,int size, Task *task);
void getnew (Task *p, int interval,int size);

int main() {
    int interval, size;
    scanf("%d %d",&size, &interval);
    int maxsize = size;
    Task task[maxsize];
    
    for(int i = 0; i < size; ++i)
    {
        scanf("%s %d", task[i].name, &task[i].quantum);
    }
//    for(int i = 1; i < size+1; i++)
//    {
//        printf("%s %d\n", task[i].name, task[i].quantum);
//
//    }
    getnew (task, interval,maxsize);
  
    return 0;
}
int enqueue(Task a,int tail,int size, Task *task)
{
    task[tail] = a;
    tail = (tail+1) % size;
    return tail;
}
Task dequeue(int head,int size, Task *task)
{
    Task a = task[head];
    return a;
}
void getnew (Task *p, int interval,int size)
{
    Task temp;
    int toltime = 0;
    int head = 0;
    int tail = size-1;
    while(head != tail){  
        temp = dequeue(head, size, p);
        head = (head+1) % size;
        if(temp.quantum <= interval)
        {
            toltime += temp.quantum;
            printf("%s %d\n",temp.name, toltime);
        }
        else 
        {
            toltime += interval;
            temp.quantum -= interval;
            tail = enqueue(temp,tail,size,p);
        }
    }
}
