#include<iostream>
#include<string>
#include<cstdlib>

#define N 100000
using namespace std;


typedef struct{
  int num[N];
  int head;
  int tail;
}Queque;


//grobal
Queque que;

  //add to head position
void push(int);
  //delete head position
void pop(void);
  //return now of stck
int front(void);


int main(){
  //format
  que.head=0;
  que.tail=0;

  int pasttime=0;
  int i,n,q,tim=0;
  string name[N];
  int finishcount=0;
  int flag[N];
  int st;

  //load n and q
  cin >>n>>q;

  //load name and time
  for(i=0;i<n;i++){
    cin >>name[i]>>tim;
    push(tim);
  }

  //format flag
  for(i=0;i<n;i++){
    flag[i]=0;
  }
  
  i=0;

  while(1){
    if(finishcount==n) break;
    //i->n i=0 continue
    else if(i==n){
      i=0;
      continue;
      }
    //flag=1 go next
      else if(flag[i]==1){
      i++;
      continue;
    }
    //load
    st=front();

    if(st>q){
      push(st-q);
      pop();
      pasttime+=q;
    }

    else{
      pop();
      pasttime+=st;
      flag[i]=1;
      finishcount++;
      //print
      cout <<name[i]<<" "<<pasttime<<endl;
    } 
    
    i++;
  }
    
  
  return 0;
  
}

  //add to head position
  void push(int x){
    que.num[que.tail]=x;
    que.tail++; 
 }
  //delete head position
  void pop(void){
    que.head++;
  }
  //return now of stck
  int front(void){
    return que.num[que.head];
  }