#include<stdio.h>
#define n_max 1000000
typedef struct{
  char name[10];
  int e_time;
}pro;
void enqueue(pro);
pro dequeue();
void exe();
int dif(pro);
int b_time;
int sum=0;
int head=0;
int tail=0;
pro pro1[n_max];
int main(){
  int i;
  int n;
  scanf("%d%d",&n,&b_time);
  tail=n;
  for(i=0;i<n;i++){
    scanf("%s%d",pro1[i].name,&pro1[i].e_time);
  }
  exe(pro1);
  return 0;
}
void enqueue(pro p){
pro1[tail]=p;
if(tail==n_max-1)tail=0;
else tail++;
}
pro dequeue(){
pro p;
p=pro1[head];
  if(head==n_max-1)head=0;
  else head++;
  return p;
}
void exe(){
  int d_f;
  pro p2;
  while(head!=tail){
    p2=dequeue();
    d_f=dif(p2);
    sum+=d_f;
    p2.e_time-=d_f;
    if(p2.e_time>0)enqueue(p2);
    else printf("%s %d\n",p2.name,sum);
  }
}
int dif(pro p){
  return p.e_time>b_time?b_time:p.e_time;
}

