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

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

P queue[QSIZE];
int head=0,tail=0;

void enqueue(P y)
{
int next=(tail+1)%QSIZE;
if(next==head){
  printf("Queue overflow\n");
  exit(2);
}
queue[tail]=y;
tail=next;
}

P dequeue(void)
{
  P x;
  if(head ==tail){
    printf("Queue is empty\n");
    exit(3);
  }
  x=queue[head];
  head=(head+1)%QSIZE;
  return x;
}

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


int main(){
  int i,n,q,time,min,sum=0;
  P a;

  scanf("%d %d",&n,&q);
  for(i=0;i<n;i++){
    scanf("%s %d",queue[i].name,&queue[i].time);
    enqueue(queue[i]);
  }
  while(head!=tail){
  a=dequeue();
  if(q<a.time) {
    a.time-=q;
    enqueue(a);
    sum+=q;
  }else{
    sum+=a.time;
    printf("%s %d\n",a.name,sum);
  }
  }
  return 0;
}

