#include <stdio.h>
#include <string.h>
typedef struct{
  char name[10];
  int time;
}P;

void enqueue(P);
P dequeue(void);
int min(int,int);

int head,tail,n;
P Q[100000];

int main(){
  int q,i,total=0,c;
  P u;

  scanf("%d%d",&n,&q);
  for(i=0;i<n;i++)
    scanf("%s%d",Q[i].name,&Q[i].time);

  head=0;
  tail=n;

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

void enqueue(P x){
  Q[tail]=x;
  if(tail==n)
    tail=0;
  else
    tail++;
}

P dequeue(void){
  P x;
  x=Q[head];

  if(head==n)
    head=0;
  else
    head++;
  return x;
}

int min(int a,int b){
  if(a>=b)
    return b;
  else return a;
}