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

#define  LEN 100000

struct queue
{
    char name[10];
    int t;
};

struct queue Q[LEN];
int head, tail, n, q;

void enqueue(struct queue x)
{
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

struct queue dequeue()
{
    struct queue x = Q[head];
    
    head = (head + 1) % LEN;

    return x;
}

int main()
{
    int count = 0;
    scanf("%d", &n);
    scanf("%d", &q);

    for (int i = 0; i < n; i++)
    {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    
    head = 0;
    tail = n;
    while (head != tail)
    {
        struct queue x;

        x = dequeue();
        if(x.t > q)
        {
            x.t = x.t - q;
            count = count + q;
            enqueue(x);
        } else
        {
            count = count + x.t;
            printf("%s %d\n", x.name, count);
        }
        
    }
    
    return 0;
}


