#include <stdio.h>
#define N 100000

typedef struct q{
  char name[10];
  int time;
}qoo;

qoo Q[N];
int head,tail,n;

void enq(qoo);
qoo deq();
int min(int,int);

int main(){
  qoo z;
  int q,i;
  int p = 0,c;

  scanf("%d %d",&n,&q);
  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].time);
  }
  head=1;
  tail=n+1;

  while(head!=tail){
    z=deq();
    c=min(q,z.time);
    z.time-=c;
    p+=c;
    if(z.time>0)enq(z);
    else printf("%s %d\n",z.name,p);
  }

  return 0;
}


void enq(qoo x){
  Q[tail] = x;
  tail = (tail+1)%N; 
}
qoo deq(){
  qoo x = Q[head];
  head = (head+1)%N;
  return x;
}
int min(int a,int b)
{return a < b ? a : b;}

