#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 100001

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

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

int isEmpty(){
  if(head==tail) return 1;
  return 0;
}

int isFull(){
  if(head==((tail+1)%MAX)) return 1;
  return 0;
}

void enqueue(char name[],int time){
  if(isFull()) printf("error\n");
  strcpy(Q[tail].name,name);
  Q[tail].t = time;
  if((tail+1)==MAX) tail=0;
  else tail++;
}

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

void line(){
  int total=0;
  while(!isEmpty()){
    if(Q[head].t>q){
      Q[head].t-=q;
      P tmpc=dequeue();
      enqueue(tmpc.name,tmpc.t);
      total+=q;
    }else{
      total+=Q[head].t;
      printf("%s %d\n",Q[head].name,total);
      dequeue();
    }
  }
}

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


  scanf("%d%d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s%d",Q[i].name,&Q[i].t);
    enqueue(Q[i].name,Q[i].t);
  }
  line();
  return 0;
}

