#include <stdio.h>

typedef struct 
{
  int number;
  char name[10];
} queue;
queue Q[100000];

int head,tail=0;
void enqueue(queue);
queue dequeue(void);

int main()
{
    int n,q,t=0,i,number;
    queue in;

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

    return 0;
}

void enqueue(queue in)
{
 Q[tail]=in;
 tail = (tail +1)%100000;
} 

queue dequeue(void)
{
    queue a;
    a=Q[head];
    head=(head+1)%100000;
 return a;
}
