#include <stdio.h>
#include <stdlib.h>
#define MAX 100000
typedef struct pp{
  char name[100];
  int t;
}P;

P Q1[MAX+1],Q2[MAX+1];

void initialize(void);
int isEmpty(void);
int isFull(void);
void enqueue(P x);
P dequeue(void);
int tail,head,n;
int main(){
  int x,time=0,i,t;
  char elaps[100];
  P q;
  scanf("%d %d",&n,&t);

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

void initialize(void){
  head = tail = 0;
}

int isEmpty(void){
  if( head == tail)return 0;//kara
  else return 1;
}
int isFull(void){
  if (head == (tail+1) % MAX) return 0; //manpai
  else return 1;
}
void enqueue(P x){

  if(isFull()== 0){
    fprintf(stderr,"??¨?????????????????????????????????\n");
    exit(8);
  }
  Q2[tail] = x;
  if(tail ==n+1)tail=0;
  else tail++;
}
P  dequeue(void){
  P x;
  if(isEmpty()== 0){
    fprintf(stderr,"??¨???????????¢?????????????????????\n");
    exit(8);
  }
  x = Q2[head];
  if (head ==n+1)head = 0;
  else head++;
  return x;