#include<stdio.h>
#include<string.h>
#define N 100005
 
typedef struct Name
{

  char name[100];
  int t;

} Name;
 
Name dequeue();

int min();
void enqueue();

Name Q[N];

int head,tail,n;
 
int main(){

  int e=0,c,i,q;
  Name x;

  scanf("%d%d",&n,&q);

  for(i=1;i<=n;i++){

    scanf("%s",Q[i].name);

    scanf("%d",&Q[i].t);

  }
  
  head = 1;
  tail = n+1;
  
  while( head != tail ){

    x = dequeue();

    c = min(q,x.t);

    x.t=x.t-c;

    e = e + c;

    if( x.t > 0 ) enqueue(x);

    else printf("%s %d\n",x.name,e);

  }

  return 0;
}
 
void enqueue( Name x ){

  Q[tail] = x;
  tail = (tail+1) % N;

}
 
Name dequeue(){

  Name x;
  x = Q[head];
  head=(head+1) % N;
  return x;
}
 
int min(int a,int b){

  return a < b ? a : b;

}