#include <stdio.h>
#include <string.h>
#define LEN 100006

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

process  q[100006]; 
int head,tail,n;
void enqueue();
process dequeue();


int main(){
  int n,qu,i,j,ti,ans = 0;
  process p;
  scanf("%d%d",&n,&qu);
  head = 1;
  tail = n + 1;


  for(i = 1;i <= n;i++){
    scanf("%s",q[i].name);
    scanf("%d",&q[i].t);
  }
  
  while(tail != head){
    p = dequeue();
    if(p.t > qu){
      ans += qu;
      p.t -= qu;
      enqueue(p);
    }
    else{
      ans += p.t;
      printf("%s %d\n",p.name,ans);
    }
  }
    
  return 0;
}

void  enqueue( process in){
   q[tail] = in;
   tail = (tail + 1) % LEN;
 }

process dequeue(){
  process out;
  out = q[head];
  head = (head + 1) % LEN;
  return out;
}