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

typedef struct PP{
    char name[1000];
    int time;
}P;

void initialize();
void enqueue(P);
P dequeue();
int min(int, int);

P Q[MAX];
int head,tail;

int main()
{
    int elaps=0,c;
    int n,q,i;
    P u;
    initialize();
    scanf("%d%d",&n,&q);

    for(i=1;i<=n;i++)
    {
        scanf("%s",Q[i].name);
        scanf("%d",&Q[i].time);
    }
    head = 1;
    tail = n+1;
    
    while(head!=tail)
    {
        u = dequeue();
        c = min(q, u.time); //qまたは必要な時間u.timeを処理
        u.time -= c; //残りの必要な時間
        elaps += c;  //経過時間
        if(u.time > 0)
        {
            enqueue(u);
        }
        else
        {
            printf("%s %d\n",u.name, elaps);
        }
    }
    return 0;
}

void initialize()
{
    head = tail = 0;
}

void enqueue(P x)
{
    Q[tail] = x;
    if(tail+1==MAX)
    {
        tail = 0;
    }
    else tail++;
}

P dequeue()
{
    P tmp;
    tmp = Q[head];
    if(head+1==MAX)
    {
        head = 0;
    }
    else head++;
    return tmp;
}

int min(a, b)
{
    if(a>b) return b;
    if(a<=b) return a; 
    return 0;
}
