import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

  public static void main(String args[]) throws IOException{
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  String[] string =  br.readLine().split(" ");
      int n = Integer.parseInt (string[0]);
	  int Quantum = Integer.parseInt(string[1]);

	  Queue queue = new Queue();
	  queue.initialize();

	  for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  }

	  int pasttime = 0;
	  while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  }

 }
}

class Queue{
    int head , tail;
    int MAX = 100000;
    String[] Q = new String[MAX];


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

    boolean isEmpty(){
    	return head == tail;
    }

    boolean isFull(){
    	return  head == (tail + 1) % MAX;
    }

    void enqueue(String x){
    	if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	}
    	 Q[tail] = x;

    	if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	}

    }

    String dequeue(){
    	if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	}
    	String x = Q[head];

    	if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    }
        return x;
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {

  public static void main(String args[]) throws IOException{
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  String[] string =  br.readLine().split(" ");
      int n = Integer.parseInt (string[0]);
	  int Quantum = Integer.parseInt(string[1]);

	  Queue queue = new Queue();
	  queue.initialize();

	  for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  }

	  int pasttime = 0;
	  while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  }

 }
} Main public static void main(String args[]) throws IOException{
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  String[] string =  br.readLine().split(" ");
      int n = Integer.parseInt (string[0]);
	  int Quantum = Integer.parseInt(string[1]);

	  Queue queue = new Queue();
	  queue.initialize();

	  for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  }

	  int pasttime = 0;
	  while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  }

 } main {
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  String[] string =  br.readLine().split(" ");
      int n = Integer.parseInt (string[0]);
	  int Quantum = Integer.parseInt(string[1]);

	  Queue queue = new Queue();
	  queue.initialize();

	  for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  }

	  int pasttime = 0;
	  while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  }

 } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] string =  br.readLine().split(" "); string br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt (string[0]); n Integer.parseInt (string[0]) Integer.parseInt Integer string[0] string 0 int Quantum = Integer.parseInt(string[1]); Quantum Integer.parseInt(string[1]) Integer.parseInt Integer string[1] string 1 Queue queue = new Queue(); queue new Queue() queue.initialize() queue.initialize queue for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		  String date =  br.readLine();
		  queue.enqueue(date);
	  } {
		  String date =  br.readLine();
		  queue.enqueue(date);
	  } String date =  br.readLine(); date br.readLine() br.readLine br queue.enqueue(date) queue.enqueue queue date int pasttime = 0; pasttime 0 while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  } queue.isEmpty() == false queue.isEmpty() queue.isEmpty queue false {
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  } String[] tmpstring = queue.dequeue().split(" "); tmpstring queue.dequeue().split(" ") queue.dequeue().split queue.dequeue() queue.dequeue queue " " int tmptime = Integer.parseInt(tmpstring[1]); tmptime Integer.parseInt(tmpstring[1]) Integer.parseInt Integer tmpstring[1] tmpstring 1 if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          } tmptime > Quantum tmptime Quantum {
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          } pasttime += Quantum pasttime Quantum String time = String.valueOf( tmptime - Quantum); time String.valueOf( tmptime - Quantum) String.valueOf String tmptime - Quantum tmptime Quantum queue.enqueue(tmpstring[0]+" "+time) queue.enqueue queue tmpstring[0]+" "+time tmpstring[0]+" "+time tmpstring[0] tmpstring 0 " " time {
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          } pasttime += tmptime pasttime tmptime System.out.println(tmpstring[0]+" "+pasttime) System.out.println System.out System System.out tmpstring[0]+" "+pasttime tmpstring[0]+" "+pasttime tmpstring[0] tmpstring 0 " " pasttime String args[] args class Queue{
    int head , tail;
    int MAX = 100000;
    String[] Q = new String[MAX];


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

    boolean isEmpty(){
    	return head == tail;
    }

    boolean isFull(){
    	return  head == (tail + 1) % MAX;
    }

    void enqueue(String x){
    	if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	}
    	 Q[tail] = x;

    	if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	}

    }

    String dequeue(){
    	if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	}
    	String x = Q[head];

    	if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    }
        return x;
    }
} Queue int head head tail; tail int MAX = 100000; MAX 100000 String[] Q = new String[MAX]; Q new String[MAX] MAX void initialize(){
    	head = tail = 0;
    } initialize {
    	head = tail = 0;
    } head = tail = 0 head tail = 0 tail 0 boolean isEmpty(){
    	return head == tail;
    } isEmpty {
    	return head == tail;
    } return head == tail; head == tail head tail boolean isFull(){
    	return  head == (tail + 1) % MAX;
    } isFull {
    	return  head == (tail + 1) % MAX;
    } return  head == (tail + 1) % MAX; head == (tail + 1) % MAX head (tail + 1) % MAX (tail + 1) tail 1 MAX void enqueue(String x){
    	if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	}
    	 Q[tail] = x;

    	if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	}

    } enqueue {
    	if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	}
    	 Q[tail] = x;

    	if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	}

    } if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	} isFull() isFull {
    		System.out.println(" ??¨?????????????????????????????????");
    	} System.out.println(" ??¨?????????????????????????????????") System.out.println System.out System System.out " ??¨?????????????????????????????????" Q[tail] = x Q[tail] Q tail x if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	} tail + 1 == MAX tail + 1 tail 1 MAX {
    		 tail = 0;
    	} tail = 0 tail 0 {
    		 tail++;
    	} tail++ tail String x x String dequeue(){
    	if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	}
    	String x = Q[head];

    	if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    }
        return x;
    } dequeue {
    	if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	}
    	String x = Q[head];

    	if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    }
        return x;
    } if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	} isEmpty() isEmpty {
    		System.out.println(" ??¨???????????¢?????????????????????");
    	} System.out.println(" ??¨???????????¢?????????????????????") System.out.println System.out System System.out " ??¨???????????¢?????????????????????" String x = Q[head]; x Q[head] Q head if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    } head + 1 == MAX head + 1 head 1 MAX {
    		head = 0;
   	    } head = 0 head 0 {
   	     head++;
   	    } head++ head return x; x
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

  public static void main(String args[]) throws IOException{
	  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	  String[] string =  br.readLine().split(" ");
      int n = Integer.parseInt (string[0]);
	  int Quantum = Integer.parseInt(string[1]);

	  Queue queue = new Queue();
	  queue.initialize();

	  for(int i = 0;i < n; i++){
		  String date =  br.readLine();
		  queue.enqueue(date);
	  }

	  int pasttime = 0;
	  while( queue.isEmpty() == false){
          String[] tmpstring = queue.dequeue().split(" ");
          //System.out.println(tmpstring[0]+ " " + tmpstring[1]);
          int tmptime = Integer.parseInt(tmpstring[1]);

          if( tmptime > Quantum ){
              pasttime += Quantum;
              String time = String.valueOf( tmptime - Quantum);
              queue.enqueue(tmpstring[0]+" "+time);

          }
          else{
        	  pasttime += tmptime;
        	  System.out.println(tmpstring[0]+" "+pasttime);
          }
	  }

 }
}

class Queue{
    int head , tail;
    int MAX = 100000;
    String[] Q = new String[MAX];


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

    boolean isEmpty(){
    	return head == tail;
    }

    boolean isFull(){
    	return  head == (tail + 1) % MAX;
    }

    void enqueue(String x){
    	if( isFull() ){
    		System.out.println(" ??¨?????????????????????????????????");
    	}
    	 Q[tail] = x;

    	if(tail + 1 == MAX){
    		 tail = 0;
    	}else{
    		 tail++;
    	}

    }

    String dequeue(){
    	if( isEmpty() ){
    		System.out.println(" ??¨???????????¢?????????????????????");
    	}
    	String x = Q[head];

    	if(head + 1 == MAX){
    		head = 0;
   	    }else{
   	     head++;
   	    }
        return x;
    }
}