#include <stdio.h>
#include <stdlib.h>
#define NUM 100000

typedef struct pp{
    char name[100];
    int t;
} P;

void enqueue(P);
P dequeue(void);
void initialize(void);
int isEmpty(void);
int isFull(void);

int n,head = 0,tail = 0;
P Q[NUM];

int main()
{
    int q,total = 0;
    int i;
    P u;
    initialize();
    scanf("%d %d",&n,&q);
    
    for(i = 0;i < n;i++){
        scanf("%s %d",u.name,&u.t);
        enqueue(u);
    }
  
    while(isEmpty() != 1){
        u = dequeue();
        if(u.t > q){
            total += q;
            u.t -= q;
            enqueue(u);
        }
        else{
            total += u.t;
            printf("%s %d\n",u.name,total);
        }
    }
    return 0;
}

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

int isEmpty(void)
{
    return head == tail;
}

int isFull(void)
{
    return head == (tail+1) % (n+1);
}

void enqueue(P x)
{
    if(isFull()){
        printf("overflow\n");
        exit(1);
    }
    Q[tail] = x;
    if(tail == n) tail = 0;
    else tail++;
}

P dequeue(void)
{
    P x;
    if(isEmpty()){
        printf("underflow\n");
        exit(2);
    }
    x = Q[head];
    if(head+1 == n+1) head = 0;
    else head++;
    return x;
}

