#include <stdio.h>
#define LEN 100005

struct process {
    char name[100];
    int ntime;
};
struct process A[LEN];
int head,tail;


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

struct process dequeue()
{
    struct process x = A[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b)
{
    return a < b ? a : b;
}

int main() {
    struct process y;
    int n,q,i,c,t=0;

    scanf("%d %d", &n,&q);
    for ( i = 0; i < n; ++i) {
        scanf("%s",A[i].name);
        scanf("%d",&A[i].ntime);
    }
    head = 0; tail = n;
    while (head != tail) {
        y = dequeue();
        c = min(q,y.ntime);
        y.ntime -= c;
        t += c;
        if (y.ntime > 0) enqueue(y);
        else printf("%s %d\n",y.name,t);
    }
    return 0;
}
