#include<stdio.h>
#include<stdlib.h>
#define LEN 100005

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

void enqueue(P);
P dequeue(void);

P queue[LEN];
int head ,tail;
int n;

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

  for ( i = 1; i <= n; i++){
    scanf("%s", queue[i].name);
    scanf("%d", &queue[i].t);
  }

head = 1;
tail = n+1;

while(head != tail)
{
u=dequeue();
    if(u.t>=q)
    c = q;
    else
    c = u.t;
u.t-=c;
elaps+=c;
if(u.t>0)enqueue(u);
else 
{printf("%s %d\n",u.name,elaps);}
}
  return 0;
}

void enqueue(P x)
{
    int next = (tail+1)%LEN;

    if(next == head){
        printf("Queue overflow\n");
        exit(2);
    }
    queue[tail] = x;
    tail = next;
}

P dequeue(void)
{
    P val;

    if(head == tail){
        printf("Queue is empty\n");
        exit(3);
    }
    val=queue[head];
    head=(head+1)%LEN;
    return val;
}
