#include<stdio.h>
#include<string.h>
#define MAX 100005

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

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

P Q[MAX+1];
int head=1,tail,n;

void enqueue(P x){
  Q[tail]=x;
  if(tail!=MAX){
    tail++;
  } else {
    tail=1;
  }
}

P dequeue(){
  P x;
  x=Q[head];
  if(head!=MAX){
    head++;
  } else {
    head=1;
  } 
  return x;
}


int main(){
  int i,j,s,e=0;
  P u;
  scanf("%d%d",&n,&j);
  for(i=1;i<= n;i++) scanf("%s %d",Q[i].name,&Q[i].t); 
  
  tail=n+1;

  while(head!=tail){
    u=dequeue();
    s=min(j,u.t);
    u.t-=s;
    e+=s;
    if(u.t<=0){
      printf("%s %d\n",u.name,e);
    }
    else if(u.t>0){
      enqueue(u);
    }
  }
  return 0;
}