#include <stdio.h>
#define MAX 99999
int head, tail;
typedef struct {
char name[10];
int time;} MISSION;

MISSION T[MAX];

void enqueue(MISSION x)
{
    T[tail] = x;
    tail = (tail + 1) % MAX;
}

MISSION dequeue()
{
    MISSION x;
    x = T[head];
    head = (head +1) % MAX;
    return x;
}

int main()
{
    int n, q;
    scanf("%d%d", &n, &q);
    for(int i = 0; i< n;i++)
        scanf(" %s %d", &T[i].name,&T[i].time);
    head = 0;
    tail = n;
    int ttime=0;
    while(head != tail)
   {
       MISSION  X = dequeue();
       if (X.time > q)
       {X.time -=q;
       ttime += q;
       enqueue(X);}
       else if(X.time <= q)
       {
           ttime += X.time;
            printf("%s %d\n", X.name, ttime);
       }
   }
    return 0;
}

